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";

 

posted @ 2023-10-26 14:04  天使不设防  阅读(20)  评论(0编辑  收藏  举报