Perl | shift() Function - GeeksforGeeks

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

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



請為這篇文章評分?