如果你自己写了一个perl脚本,指定传入参数,如:xxxscript.pl -f <filename> -s <string>
则可以通过下面的代码解决:
#-------------------------------------------------------------------------
# 解析输入参数
sub process_args {
while (@ARGV) {
$a = shift @ARGV;
if ($a eq "-h") {
Usage();
} elsif ($a eq "-f") {
$file= shift @ARGV;
} elsif ($a eq "-s") {
$string= shift @ARGV ;
} else {
Usage();
}
}
}
本文详细介绍了如何在Perl脚本中解析输入参数,通过使用自定义子过程,实现对命令行参数的灵活处理。

884

被折叠的 条评论
为什么被折叠?



