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 @   天使不设防  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示