shift @ARGV not working - PerlMonks
文章推薦指數: 80 %
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
延伸文章資訊
- 1Perl中shift函数用法 - CSDN博客
数组也被改变,其第一个元素被弹出。 如果没有array,直接给变量赋值shift. @ARGV: perl 命令行参数. 当运行perl脚本的时候,从 ...
- 2Processing command line arguments - @ARGV in Perl
In Perl @ARGV contains the raw command line arguments as passed by the user ... You can also use ...
- 3shift in Perl - Perl Maven
The shift function in Perl will remove the first value of the array passed to it and return it. ....
- 4perl shift()函數 - 極客書
定義和用法 ... 返回在一個數組中的第一個值,刪除和移位到左邊的元素數組列表一個位置。如果未指定數組ARRAY,轉移@_數組內的子程序,或@ARGV以其他方式。移位彈出本質上是 ...
- 5defaults to shifting @ARGV : Special Variables - Perl
#!/usr/bin/perl -w use strict; sub version { print "version\n"; } my $option = shift; # defaults ...