What does "last" do in Perl? - Stack Overflow
文章推薦指數: 80 %
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
延伸文章資訊
- 1精簡扼要的Perl 課程講義(三):迴圈與控制結構 - G. T. Wang
next 跳到這裡 } # last 跳到這裡繼續執行 # 註:next, last 與redo 皆可用在for,foreach,while 與until 等迴圈。 # (7) if # (A)...
- 25.7 迴圈控制
Perl 常見的迴圈有while、for、foreach、until,在每一種迴圈中,可以視情況,使用以下三種算符,來控制迴圈。 last 一次只能跳出一層迴圈語法:last 用例: $i=0;...
- 3Perl last关键字 - 极客书
perl last 关键字学习例子,last实例代码,在线教程等. ... 不是一个函数。last关键字立即使循环当前迭代,成为最后一个循环控制语句。没有进一步的语句被执行,并结束 ...
- 4last - Perldoc Browser
If the LABEL is omitted, the command refers to the innermost enclosing loop. The last EXPR form, ...
- 5Perl last 语句 - 菜鸟教程
Perl last 语句Perl 循环Perl last 语句用于退出循环语句块,从而结束循环,last语句之后的语句不再执行,continue语句块也不再执行。 语法语法格式如下所示: las...