Perl | Use of STDIN for Input - GeeksforGeeks

文章推薦指數: 80 %
投票人數:10人

Input to a Perl program can be given by keyboard with the use of . Here, STDIN stands for Standard Input . Though there is no need to ... Skiptocontent CoursesForWorkingProfessionalsDSAClasses(Live)SystemDesign(Live)JavaBackendDeveloper(Live)FullStack(Live)ExploreMoreLiveCoursesDSA(Self-Paced)SDETheory(Self-Paced)AllDevelopmentCourses(Self-Paced)ExploreMoreSelf-PacedCoursesForStudentsCompetitiveProgramming(Live)GATECourse2023(Live)DataScience(Live)ExploreMoreLiveCoursesDSA(Self-Paced)CIP(Self-Paced)JAVA/Python/C++(Self-Paced)ExploreMoreSelf-PacedCoursesSchoolCoursesSchoolGuidePythonProgrammingLearnToMakeAppsExploremoreAllCoursesTutorialsAlgorithmsAnalysisofAlgorithmsAsymptoticAnalysisWorst,AverageandBestCasesAsymptoticNotationsLittleoandlittleomeganotationsLowerandUpperBoundTheoryAnalysisofLoopsSolvingRecurrencesAmortizedAnalysisWhatdoes'SpaceComplexity'mean?Pseudo-polynomialAlgorithmsPolynomialTimeApproximationSchemeATimeComplexityQuestionSearchingAlgorithmsSortingAlgorithmsGraphAlgorithmsPatternSearchingGeometricAlgorithmsMathematicalBitwiseAlgorithmsRandomizedAlgorithmsGreedyAlgorithmsDynamicProgrammingDivideandConquerBacktrackingBranchandBoundAllAlgorithmsDataStructuresArraysLinkedListStackQueueBinaryTreeBinarySearchTreeHeapHashingGraphAdvancedDataStructureMatrixStringsAllDataStructuresInterviewCornerCompanyPreparationTopTopicsPracticeCompanyQuestionsInterviewExperiencesExperiencedInterviewsInternshipInterviewsCompetititveProgrammingDesignPatternsSystemDesignTutorialMultipleChoiceQuizzesLanguagesCC++JavaPythonC#SQLScalaPerlGoLanguageKotlinWebDevelopmentHTMLCSSJavaScriptPHPCSSFrameworksBootstrapTailwindCSSFoundationCSSMaterializeCSSBulmaPureCSSPrimerCSSBlazeUISemanticUIJavaScriptFrameworksAngularJSNodeJSJavaScriptLibrariesjQueryReactJSML&DataScienceMachineLearningDataScienceCSSubjectsMathematicsOperatingSystemDBMSComputerNetworksComputerOrganizationandArchitectureTheoryofComputationCompilerDesignDigitalLogicSoftwareEngineeringGATEGATEComputerScienceNotesLastMinuteNotesGATECSSolvedPapersGATECSOriginalPapersandOfficialKeysGATE2021DatesGATECS2021SyllabusImportantTopicsforGATECSSoftwareDesignsSoftwareDesignPatternsSystemDesignTutorialGFGSheetsWebDevCheatSheetsHTMLCheatSheetCSSCheatSheetJSCheatSheetjQueryCheatSheetCompany-WiseSDESheetsFacebookSDESheetAmazonSDESheetAppleSDESheetNetflixSDESheetGoogleSDESheetWiproCodingSheetInfosysCodingSheetTCSCodingSheetCognizantCodingSheetHCLCodingSheetDSASheetsSDESheetFAANGCodingSheetLoveBabbarSheetMassRecruiterSheetProduct-BasedCodingSheetCompany-WisePreparationSheetArraySheetStringSheetTreeSheetGraphSheetDPSheetSchoolLearningSchoolProgrammingMathematicsNumberSystemAlgebraTrigonometryStatisticsProbabilityGeometryMensurationCalculusMathsNotes(Class8-12)Class8NotesClass9NotesClass10NotesClass11NotesClass12NotesNCERTSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionRDSharmaSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionPhysicsNotes(Class8-11)Class8NotesClass9NotesClass10NotesClass11NotesChemistryNotesClass8NotesClass9NotesClass10NotesBusinessStudies(Class11th)BusinessStudies(Class12th)CSExams/PSUsISROISROCSOriginalPapersandOfficialKeysISROCSSolvedPapersISROCSSyllabusforScientist/EngineerExamUGCNETUGCNETCSNotesPaperIIUGCNETCSNotesPaperIIIUGCNETCSSolvedPapersStudentCampusAmbassadorProgramSchoolAmbassadorProgramProjectGeekoftheMonthCampusGeekoftheMonthPlacementCourseCompetititveProgrammingTestimonialsStudentChapterGeekontheTopInternshipCareersUPSCGeographyNotesHistoryNotesScience&Tech.NotesEthicsNotesPolityNotesEconomicsNotesUPSCPreviousYearPapersSSCCGLSSCCGLSyllabusGeneralStudiesEnglishReasoningSubjectwisePracticePapersPreviousYearPapersBankingExamsSBIClerkSBIClerkSyllabusGeneralAwarenessEnglishQuantitativeAptitudeReasoningAbilitySBIClerkPracticePapersSBIPOSBIPOSyllabusGeneralAwarenessEnglishQuantitativeAptitudeReasoningAbilityPreviousYearPapersSBIPOPracticePapersIBPSPOIBPSPO2022SyllabusEnglishNotesReasoningNotesPreviousYearPapersMockQuestionPapersIBPSClerkIBPSClerkSyllabusEnglishNotesPreviousYearPapersJobsApplyforJobsPostaJobHirewithUsKnowaboutJobathonJobathonPracticeAllDSAProblemsProblemoftheDayInterviewSeries:WeeklyContestsBi-WizardCoding:SchoolContestsEventsPracticeSDESheetCuratedDSAListsTop50ArrayProblemsTop50StringProblemsTop50TreeProblemsTop50GraphProblemsTop50DPProblemsContests HomeSavedVideosCoursesGBlogPuzzlesWhat'sNew? ChangeLanguage DataStructuresAlgorithmsInterviewPreparationTopic-wisePracticeC++JavaPythonCompetitiveProgrammingMachineLearningWrite&EarnJavaScriptSDESheetPuzzlesGFGSchoolProjects RelatedArticles ▲RelatedArticlesWriteanArticleWriteArticlesPickTopicstowriteGuidelinestoWriteGetTechnicalWritingInternshipWriteanInterviewExperienceUseofprint()andsay()inPerlPerl|printoperatorPerl|UseofSTDINforInputPerl|STDINinScalarandListContextPerl|SortingofArraysPerl|ComparingScalarsPerl|scalarkeywordPerl|ScalarsPerl|ArraysPerl|Arrays(push,pop,shift,unshift)Perl|push()FunctionPerl|join()FunctionPerl|Loops(for,foreach,while,do…while,until,Nestedloops)Perl|DecisionMaking(if,if-else,Nested–if,if-elsifladder,unless,unless-else,unless-elsif)Perl|split()FunctionPerl|chomp()FunctionPerl|chop()FunctionPerl|Removingleadingandtrailingwhitespaces(trim)Perl|StringOperatorsPerl|Stringfunctions(length,lc,uc,index,rindex)Perl|UsefulStringfunctionsPerl|UsefulArrayfunctionsPerl|exists()FunctionPerl|grep()FunctionPerl|SearchinginaFileusingregexPerl|substr()functionWriteanArticleWriteArticlesPickTopicstowriteGuidelinestoWriteGetTechnicalWritingInternshipWriteanInterviewExperienceUseofprint()andsay()inPerlPerl|printoperatorPerl|UseofSTDINforInputPerl|STDINinScalarandListContextPerl|SortingofArraysPerl|ComparingScalarsPerl|scalarkeywordPerl|ScalarsPerl|ArraysPerl|Arrays(push,pop,shift,unshift)Perl|push()FunctionPerl|join()FunctionPerl|Loops(for,foreach,while,do…while,until,Nestedloops)Perl|DecisionMaking(if,if-else,Nested–if,if-elsifladder,unless,unless-else,unless-elsif)Perl|split()FunctionPerl|chomp()FunctionPerl|chop()FunctionPerl|Removingleadingandtrailingwhitespaces(trim)Perl|StringOperatorsPerl|Stringfunctions(length,lc,uc,index,rindex)Perl|UsefulStringfunctionsPerl|UsefulArrayfunctionsPerl|exists()FunctionPerl|grep()FunctionPerl|SearchinginaFileusingregexPerl|substr()functionPerl|UseofSTDINforInputViewDiscussion ImproveArticle SaveArticle LikeArticle DifficultyLevel: MediumLastUpdated: 24Jun,2019ReadDiscussViewDiscussion ImproveArticle SaveArticle LikeArticle Perlallowstheprogrammertoacceptinputfromtheusertoperformoperationson.ThismakesiteasierfortheusertogiveinputofitsownandnotonlytheoneprovidedasHardcodedinputbytheprogrammer.ThisInputcanthenbeprocessedandprintedwiththeuseofprint()function.InputtoaPerlprogramcanbegivenbykeyboardwiththeuseof.Here,STDINstandsforStandardInput.ThoughthereisnoneedtoputSTDINinbetweenthe‘diamond’or‘spaceship’operatori.e,<>.Itisstandardpracticetodoso.<>operatorcanbeusedtowritetofilesaswell.canbealsobeusedinScalarandListcontext.Syntax:$x=;or$x=<>;Example:#!/usr/bin/perl-w usestrict;usewarnings;  print"Entersometext:";my$string=;  print"Youentered$stringasaString";Input:GeeksForGeeksOutput:Entersometext:GeeksForGeeks YouEnteredGeeksForGeeks asaStringIntheabovecode,aftergivingInput,thereisaneedtopressENTER.ThisENTERisusedtotellthecompilertoexecutethenextlineofthecode.But,takesthisENTERkeypressedasapartoftheInputgivenandhencewhenweprinttheline.AnewlinewillautomaticallybeprintedaftertheInputstring.Toavoidthis,afunctionchomp()isused.ThisfunctionwillremovethenewlinecharacteraddedtotheendoftheInputprovidedbytheuser.Example:#!/usr/bin/perl-w usestrict;usewarnings;  print"Entersometext:";my$string=;chomp$string;  print"Youentered$stringasaString";Input:GeeksForGeeksOutput:Entersometext:GeeksForGeeks YouEnteredGeeksForGeeksasaStringMyPersonalNotes arrow_drop_upSave LikePreviousPerl|printoperatorNext Perl|STDINinScalarandListContextRecommendedArticlesPage:06,Mar1913,Jun1913,Nov1917,Jun1909,Jul1928,Jul2002,Aug1802,May1903,Jul1930,May1929,Apr1926,Apr1928,Feb1913,Jul1820,Jun1820,Jun1820,Jun1825,Jun1818,Jul1826,Jun1828,Jun1803,Jul1803,Jul1803,Jul18ArticleContributedBy:Abhinav96@Abhinav96VotefordifficultyCurrentdifficulty: MediumEasy Normal Medium Hard ExpertArticleTags:Perl-Input-OutputPerlPracticeTags:PerlReportIssueWritingcodeincomment? Pleaseuseide.geeksforgeeks.org, generatelinkandsharethelinkhere. LoadCommentsPleaseLogintocomment...What'sNew  ViewDetailsViewDetailsViewDetailsImproveyourCodingSkillswithPracticeTryIt! Weusecookiestoensureyouhavethebestbrowsingexperienceonourwebsite.Byusingoursite,you acknowledgethatyouhavereadandunderstoodour CookiePolicy& PrivacyPolicy GotIt! StartYourCodingJourneyNow!Login Register



請為這篇文章評分?