Perl | shift() Function - GeeksforGeeks
文章推薦指數: 80 %
shift() function in Perl returns the first value in an array, removing it and shifting the elements of the array list to the left by one. 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 ▲RelatedArticlesWriteanArticleWriteArticlesPickTopicstowriteGuidelinestoWriteGetTechnicalWritingInternshipWriteanInterviewExperiencePerl|shift()FunctionPerl|Arrays(push,pop,shift,unshift)Perl|ComparingScalarsPerl|scalarkeywordPerl|ScalarsPerl|ArraysPerl|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|RegularExpressionsPerl|OperatorsinRegularExpressionPerl|RegexCharacterClassesPerl|QuantifiersinRegularExpressionPerl|substr()functionWriteanArticleWriteArticlesPickTopicstowriteGuidelinestoWriteGetTechnicalWritingInternshipWriteanInterviewExperiencePerl|shift()FunctionPerl|Arrays(push,pop,shift,unshift)Perl|ComparingScalarsPerl|scalarkeywordPerl|ScalarsPerl|ArraysPerl|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|RegularExpressionsPerl|OperatorsinRegularExpressionPerl|RegexCharacterClassesPerl|QuantifiersinRegularExpressionPerl|substr()functionPerl|shift()FunctionViewDiscussion ImproveArticle SaveArticle LikeArticle LastUpdated: 07May,2019ReadDiscussViewDiscussion ImproveArticle SaveArticle LikeArticle shift()functioninPerlreturnsthefirstvalueinanarray,removingitandshiftingtheelementsofthearraylisttotheleftbyone.Shiftoperationremovesthevaluelikepopbutistakenfromthestartofthearrayinsteadoftheendasinpop.Thisfunctionreturnsundefifthearrayisemptyotherwisereturnsthefirstelementofthearray.Syntax:shift(Array)Returns:-1ifarrayisEmptyotherwisefirstelementofthearrayExample1:#!/usr/bin/perl-w #DefiningArraytobeshifted@array1=("Geeks","For","Geeks"); #OriginalArrayprint"OriginalArray:@array1\n"; #Performingtheshiftoperation$shifted_element=shift(@array1); #Printingtheshiftedelementprint"Shiftedelement:$shifted_element\n"; #UpdatedArrayprint"UpdatedArray:@array1";Output: OriginalArray:GeeksForGeeks Shiftedelement:Geeks UpdatedArray:ForGeeks Example2:#!/usr/bin/perl-w #Programtomovefirstelement #ofanarraytotheend #DefiningArraytobeshifted@array1=("Geeks","For","Geeks"); #OriginalArrayprint"OriginalArray:@array1\n"; #Performingtheshiftoperation$shifted_element=shift(@array1); #PlacingFirstelementintheend@array1[3]=$shifted_element; #UpdatedArrayprint"UpdatedArray:@array1";Output: OriginalArray:GeeksForGeeks UpdatedArray:ForGeeksGeeks MyPersonalNotes arrow_drop_upSave LikeNext Perl|Arrays(push,pop,shift,unshift)RecommendedArticlesPage:18,Feb1913,Jun1913,Nov1902,Aug1802,May1926,Apr1928,Feb1903,Jul1814,Feb1914,Feb1914,Feb1914,Feb1919,Feb1921,Feb1921,Feb1922,Feb1922,Feb1925,Feb1925,Feb1925,Feb1925,Feb1925,Feb1925,Feb1927,Feb19ArticleContributedBy:Code_Mech@Code_MechVotefordifficultyEasy Normal Medium Hard ExpertArticleTags:Perl-Array-FunctionsPerl-functionPerlPracticeTags:PerlReportIssueWritingcodeincomment? Pleaseuseide.geeksforgeeks.org, generatelinkandsharethelinkhere. LoadCommentsPleaseLogintocomment...What'sNew ViewDetailsViewDetailsViewDetailsImproveyourCodingSkillswithPracticeTryIt! Weusecookiestoensureyouhavethebestbrowsingexperienceonourwebsite.Byusingoursite,you acknowledgethatyouhavereadandunderstoodour CookiePolicy& PrivacyPolicy GotIt! StartYourCodingJourneyNow!Login Register
延伸文章資訊
- 1shift in Perl - Perl Maven
The shift function in Perl will remove the first value of the array passed to it and return it. ....
- 2Manipulating Perl arrays: shift, unshift, push, pop - Perl Maven
If you imagine the array starting on the left hand side, the shift function will move the whole a...
- 3perl程序中shift的用法 - 百度知道
看到有些perl程序写子程序submysub{my$pk=shift;}这里新定义的变量$pk,为什么要直接用shift,这里的shift起到什么作用?我只知道shift是从数组开头移除 ...
- 4Perl 學習手札- 3. 串列與陣列 - Easun.org
現在你的陣列進行了大幅度的改變,我們應該來檢查一下,當我們在進行shift運算過程中,陣列元素的變化。 我們還是用剛剛的陣列來看看完整的陣列內容: my @array = (1...10); ...
- 5perl程序中shift的用法- 组学大讲堂问答社区
perl程序中shift的用法. shift ARRAY shift. 这个函数把数组的第一个值移出并且返回它,然后把数组长度减一并且把所有的东西都顺移。