有些写程序不喜欢用Getopt::Long模块,但是一些perl脚本中有必要允许一个选项传入多个参数,比如oracle exp, analyze schema这类的脚本,需要允许一次运行export/analyze多个schema。这时候需要用push将多个值放入数组中。
==脚本==
#!/usr/bin/perl -w
#
# input_tst.pl
# Test the input usage
&get_input_parms;
foreach $schema (@schemas){
print "$schema/n";
}
sub get_input_parms {
$arg = shift(@ARGV);
while ($arg)
{
if($arg eq "-n" or $arg eq "-N")
{
push @schemas, shift(@ARGV); #用push
}
$arg = shift(@ARGV);
}
}
= 运行结果==
C:/temp1>perl input_tst.pl -n aa -n bb
aa
bb