What is array.shift() in Perl? - Educative.io

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

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.



請為這篇文章評分?