Getopt::Long
perl 模块Getopt::Long使用示例
use strict; use warnings; use Getopt::Long; my @ARGV2 = @ARGV; my $leng =10; my $data ="x.txt"; my $verb; my $help; die("error in options") unless GetOptions( "l|length=i" => \$leng, "f|file=s" => \$data, "v|verbose" => \$verb, "h|help" => \$help, ); sub usage { print <<USAGE -l|--length <number> set number of length -f|--file <str> set name of files -v|--verbose set verbose -h|--help show this help information USAGE } if($help || @ARGV2 == 0){ exit 0 if &usage(); } print "$leng\n$data\n$verb";
作者:天使不设防
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.