shift @ARGV not working - PerlMonks

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

rayh has asked for the wisdom of the Perl Monks concerning the following question: Quick one here. If called as script.pl -s, why doesn't this ... Wedon'tbitenewbieshere...much   PerlMonks   shift@ARGVnotworking byrayh(Initiate) Log inCreate a new user The Monastery Gates Seekers of Perl Wisdom Meditations Cool Uses For Perl Obfuscation Tutorials Poetry Reviews Perl News Donate Recent Threads Newest Nodes Super Search PerlMonks Discussion What's New onMay09,2013at18:37 UTC (#1032814=perlquestion:printw/replies,xml) NeedHelp?? rayhhasaskedforthewisdomofthePerlMonksconcerningthefollowingquestion: Quickonehere.Ifcalledasscript.pl-s,whydoesn'tthisprint"-s"? #!/usr/bin/perl if($ARGV[0]eq'-s'){ my$argument=shift@ARGV; } print"$argument"; [download] Iknowthecomparisonistruebuttheshiftdoesn'tseemhappy.IfItype"printshift@ARGV",Icanseethe-s.Howeveritdoesn'twanttobeassignedtoavariable.Commentonshift@ARGVnotworkingDownloadCode Repliesarelisted'BestFirst'. Re:shift@ARGVnotworking bytoolic(Bishop)onMay09,2013at18:44 UTC VariablesandScoping: #!/usr/bin/perl my$argument; if($ARGV[0]eq'-s'){ $argument=shift@ARGV; } print"$argument"; [download] Tip#1fromtheBasicdebuggingchecklist: usestrictandwarnings [reply][d/l] Re^2:shift@ARGVnotworking byrayh(Initiate)onMay09,2013at18:58 UTC Derp.Duh.Iwasgettingalittletoofancyinalargerscriptandoverlookedtheuseof"my"inanewblock.Thanks![reply] Re:shift@ARGVnotworking byblue_cowdawg(Monsignor)onMay09,2013at18:47 UTC #!/usr/bin/perl-w usestrict; foreachmy$i(0..$#ARGV){ printf"\$ARGV[%d]=\"%s\"\n",$i,$ARGV[$i]; } while(my$arg=shift@ARGV){ printf"%s\n",$arg; } # #--------------8



請為這篇文章評分?