What is array.shift() in Perl? - Educative.io
文章推薦指數: 80 %
The shift() method in Perl is used to return the first value of an array. It removes the first element and shifts the array list elements to the left by one ... SolutionsEducativeEnterpriseEnablementplatformDevelopersLearnnewtechnologiesProductsCoursesforEnterpriseSuperchargeyourengineeringteamCoursesforIndividualsWorldclasscoursesOnboardingOnboardnewhiresfasterAssessmentsMeasureyourSkillScorePersonalizedLearningPlansPersonalizedPlansforyourgoalsProjectsBuildrealworldapplicationsAnswersTrustedAnswerstoDeveloperQuestionsPricingForEnterpriseTailoredforyourteamForIndividualsStayaheadofthecurveCoursesLogInJoin forfreeTrustedanswerstodeveloperquestionsTrustedAnswerstoDeveloperQuestionsRelatedTagsarrayshiftperlcommunitycreatorWhatisarray.shift()inPerl?okwudilionyejiakuGrokkingModernSystemDesignInterviewforEngineers&ManagersAceyourSystemDesignInterviewandtakeyourcareertothenextlevel.LearntohandlethedesignofapplicationslikeNetflix,Quora,Facebook,Uber,andmanymoreina45-mininterview.LearntheRESHADEDframeworkforarchitectingweb-scaleapplicationsbydeterminingrequirements,constraints,andassumptionsbeforedivingintoastep-by-stepdesignprocess. StartLearning Overview Theshift()methodinPerlisusedtoreturnthefirstvalueofanarray.Itremovesthefirstelementandshiftsthearraylistelementstotheleftbyone. Syntax shift(@arr) Parameters @arr:Thisisthearraywhoseelementswewanttoshift. Returnvalue Itreturnsthefirstelementofthearrayafterremovingitfromthearray.However,ifthearrayisempty,itreturns-1. Codeexample #createanarray@arr=("e","a","b","c","d");#printarrayvaluesprint"Beforeshift:@arr\n";#shiftelement@shifted_element=shift(@arr);#printshiftedelementprint"ShiftedElement:@shifted_element";#printarrayvaluesprint"\nAftershift:@arr";RunShiftinganelementfromanarrayinPerlExplanation Line2:Wecreateanarraycalledarr. Line5:Weprintthevaluesofarrtotheconsole. Line8:Weshiftthefirstelementofthearraywecreatedwiththeshift()method. Line11:Weprinttheshiftedelement. Line14:Weprintthehenewvaluesofthearrayaftertheshifttotheconsole. RELATEDTAGSarrayshiftperlcommunitycreatorCONTRIBUTORokwudilionyejiakuLicense:CreativeCommons-Attribution-ShareAlike4.0(CC-BY-SA4.0)GrokkingModernSystemDesignInterviewforEngineers&ManagersAceyourSystemDesignInterviewandtakeyourcareertothenextlevel.LearntohandlethedesignofapplicationslikeNetflix,Quora,Facebook,Uber,andmanymoreina45-mininterview.LearntheRESHADEDframeworkforarchitectingweb-scaleapplicationsbydeterminingrequirements,constraints,andassumptionsbeforedivingintoastep-by-stepdesignprocess. StartLearningKeepExploringRelatedCoursesLearnin-demandtechskillsinhalfthetimeSOLUTIONSForEnterpriseForIndividualsForHR&ducativeSessionsEducativeAnswersABOUTUSOurTeamCareersHiringFrequentlyAskedQuestionsContactUsPressMOREGitHubStudentsScholarshipCourseCatalogEarlyAccessCoursesEarnReferralCreditsCodingInterview.comCopyright©2022Educative,Inc.Allrightsreserved.
延伸文章資訊
- 1Perl | Arrays (push, pop, shift, unshift) - GeeksforGeeks
This function returns the first value in an array, removing it and shifting the elements of the a...
- 2perl shift()函數 - 極客書
perl shift()函數例子,shift()函數實例代碼- 返回在一個數組中的第一個值,刪除和移位到左邊的元素數組列表一個位置。 語法. shift ( [ARRAY] ). shift. ...
- 3Perl shift Function - Tutorialspoint
Perl shift Function, This function returns the first value in an array, deleting it and shifting ...
- 4Perl shift | Working and examples of shift() function in Perl
In Perl, shift() function is defined as a function for shifting the elements or items in an array...
- 5shift - Perldoc Browser
Shifts the first value of the array off and returns it, shortening the array by ... Starting with...