What does "last" do in Perl? - Stack Overflow

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

Available uses for last command: ... According to Perl's documentation: The last command is like the break statement in C (as used in loops); it ... Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam StackOverflowforTeamsismovingtoitsowndomain!Whenthemigrationiscomplete,youwillaccessyourTeamsatstackoverflowteams.com,andtheywillnolongerappearintheleftsidebaronstackoverflow.com. Checkyouremailforupdates. Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. LearnmoreaboutCollectives Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams Whatdoes"last"doinPerl? AskQuestion Asked 6years,3monthsago Modified 6years,3monthsago Viewed 5ktimes 5 New!Savequestionsoranswersandorganizeyourfavoritecontent.Learnmore. Inthecodebelow,whatdoeslastdointhewhileloop?Igetthatifthe$matrix[$i][$j]{pointer}variableequals"none"itcallslastbutwhatdoesitdo? Alsowhydoesthe$matrixvariableincludescoreandpointerusingcurlybraces?{score},Ireadthisasthe3rddimensioninanarray,butisthissomethingelse?Couldn'tfindanythingongoogleaboutthis.Thanks! my@matrix; $matrix[0][0]{score}=0; $matrix[0][0]{pointer}="none"; #populate$matrixwithmorestuff while(1){ lastif$matrix[$i][$j]{pointer}eq"none";#){ lastLINEif/^$/;#exitwhendonewithheader #... } lastcannotbeusedtoexitablockthatreturnsavaluesuchaseval {},sub{},ordo{},andshouldnotbeusedtoexitagrepormap operation.Notethatablockbyitselfissemanticallyidenticaltoa loopthatexecutesonce.Thuslastcanbeusedtoeffectanearlyexit outofsuchablock. Share Improvethisanswer Follow answeredJul3,2016at13:32 AvihooMamkaAvihooMamka 4,52633goldbadges3030silverbadges4242bronzebadges Addacomment  |  11 Youhaveananswer,aboutlastbutIthoughtI'dsharethisimagewhichillustrateshownext,lastandredoaffectlogicflowinPerlloops: Acontinueblockcanoptionallybeaddedtoalooptodefinesomestatementswhichwillberunoneachiterationbeforeloopingbackuptothetoptore-evaluatetheloopcondition.Ifthereisnocontinueblock,nextwillgostraightbackuptotheloopcondition. Share Improvethisanswer Follow answeredJul4,2016at21:17 GrantMcLeanGrantMcLean 6,79811goldbadge2020silverbadges3636bronzebadges Addacomment  |  1 Asyou'vealreadygottenanansweraboutlast,I'lladdressthesecondpartofyourquestion.Perlhasarraysandhashtables(alsoknownasdictionaries).@matrixatthetoplevelisanarray,butthenitsbeinginitializedwithanotherarray,andtheelementinthatsecondarrayisbeinginitializedwithahashtable. IfyouusedData::Dumpertoprintthisout,orexporteditasJSONyou'dseesomethinglike: @matrix=[ [ {score=>0, pointer=>'none' } ] ]; Share Improvethisanswer Follow answeredJul4,2016at2:09 woolstarwoolstar 5,0531919silverbadges3131bronzebadges Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedperloraskyourownquestion. TheOverflowBlog IntroducingtheOverflowOfflineproject Hehelpedbuild.NETandVSCode—Now’sheworkingonWeb3(Ep.499) FeaturedonMeta The2022Community-a-thonhasbegun! Mobileappinfrastructurebeingdecommissioned CollectivesUpdate:RecognizedMembers,Articles,andGitLab The[script]tagisbeingburninated StagingGroundWorkflow:CannedComments Linked 317 HowdoIbreakoutofaloopinPerl? Related 77 Whatdoesshift()doinPerl? 204 Whatisthedifferencebetween'my'and'our'inPerl? 749 HowtofixalocalesettingwarningfromPerl 585 WhydoesmodernPerlavoidUTF-8bydefault? 270 FindsizeofanarrayinPerl 3 whatdoes$#acceptasinputinperl? 3 Viisn'thandlingcurlybracesinmyperlscriptcorrectly 1 ExtraunexpectedcharactersPerl HotNetworkQuestions Arelawswrittenlogicallyandrigorously? Howtohelpadev,whoisotherwisegood,improvethespeedatwhichtheywork? Whyarefangsofgirlssocommoninanime? Whichoneisbetter"hadbrokendown"or"hadbeenbrokendown"? Whyaretheredollaramountslistednearthecopyrightinformationforjournalarticles? DidtheDudeeverhaveanoccupationotherthanunemployed? Whatwouldan"excessivelysober"dwarflooklikeiftheyneedalcoholtofunction? Whywouldaplaneflyincircles? Whataredisadvantagesofaerodropbars? HowdoIlabelatablelikethis? StudentsdoubttheusefulnessofthePresentPerfecttenses WhyareUKprimeministersresigning,ratherthanwaitingouttheirtermandenjoyingthebenefits? Wouldlanguagehavemeaningiftherewasnoconsciousness? Idealprogramminglanguageforanoperationsresearcher Nomatchingfunctionforcallto'DS3231(constuint8_t&,constuint8_t&) Whatisthemostefficientwaytoget110Vfrom220Vsingle-phasewiring? WhywasThor'shammerneverusedagain? Whatis"gallowsflesh?" DoRSAsignaturesreallyneedpadding? AlphabetChecksum Howtoobtainaminor'spassportwithanabsentparent Controlthezscaleofinstanceswithempty Changingnumberformatsinstrings WhatisaScrumMastertodowhenmanagementdonotsupportAgileandScrum? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-perl Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?