shift in Perl - Perl Maven
文章推薦指數: 80 %
The shift function in Perl will remove the first value of the array passed to it and return it. ... Note, the array itself got shorter. The first element was ... Togglenavigation PerlMaven PerlTutorial Pro Login Register Books Typekeyword: Archive About shiftinPerl shift @ARGV @_ TheshiftfunctioninPerlwillremovethefirstvalueofthearraypassedtoitandreturnit. my@names=('Foo','Bar','Moo'); my$first=shift@names; print"$first\n";#Foo print"@names\n";#BarMoo Note,thearrayitselfgotshorter.Thefirstelementwasremovedfromit! shiftwithoutparameters Incasenoarrayispassedtoit,shifthastwodefaultsdependingonthelocationofshift. Ifshiftisoutsideanyfunctionittakesthefirstelementof@ARGV(theparameterlistoftheprogram). examples/shift_argv.pl usestrict; usewarnings; my$first=shift; print"$first\n"; $perlexamples/shift_argv.plonetwo one Ifshiftisinsideafunctionittakesthefirstelementof@_(theparameterlistofthefunction). examples/shift_in_sub.pl usestrict; usewarnings; subsomething{ my$first=shift; print"$first\n"; } something('hello','world'); $perlexamples/shift_in_sub.plonetwo hello Hereshiftdisregardedthecontentof@ARGVandtookthefirstelementof@_,thearray holdingtheparameterspassedtothefunction. Shiftonemptyarray Ifthearrayshiftworksonisempty,thenshiftwillreturnundef. Regardlessifthearraywasexplicitelygiventoitorimplicelyselectedbasedonthelocationofshift. Seevideoexplainingshiftandunshift ortheexampleusingshifttogetfirstparameterofascript. Writtenby GaborSzabo Publishedon2015-12-17 Comments Inthecomments,pleasewrapyourcodesnippetswithin
tagsandusespacesforindentation. commentspoweredbyDisqus Ifyouhaveanycommentsorquestions,feelfreetopostthemonthesourceofthispageinGitHub.SourceonGitHub. Commentonthispost Author:GaborSzabo GaborwhorunsthePerlMavensitehelpscompaniessetuptestautomation,CI/CD ContinuousIntegrationandContinuousDeploymentandotherDevOpsrelated systems. GaborcanhelprefactoryouroldPerlcode-base. HerunsthePerlWeeklynewsletter. ContactGaborifyou'dliketohirehisservice. BuyhiseBooksorifyoujustwouldliketosupporthim,doitviaPatreon.延伸文章資訊
- 1Manipulating Perl arrays: shift, unshift, push, pop - Perl Maven
If you imagine the array starting on the left hand side, the shift function will move the whole a...
- 2Perl 學習手札- 3. 串列與陣列 - Easun.org
現在你的陣列進行了大幅度的改變,我們應該來檢查一下,當我們在進行shift運算過程中,陣列元素的變化。 我們還是用剛剛的陣列來看看完整的陣列內容: my @array = (1...10); ...
- 3perl程序中shift的用法- 组学大讲堂问答社区
perl程序中shift的用法. shift ARRAY shift. 这个函数把数组的第一个值移出并且返回它,然后把数组长度减一并且把所有的东西都顺移。
- 4perl shift()函數 - 極客書
perl shift()函數例子,shift()函數實例代碼- 返回在一個數組中的第一個值,刪除和移位到左邊的元素數組列表一個位置。 語法. shift ( [ARRAY] ). shift. ...
- 5Perl中shift函数用法 - CSDN博客
数组也被改变,其第一个元素被弹出。 如果没有array,直接给变量赋值shift. @ARGV: perl 命令行参数. 当运行perl脚本的时候,从 ...