微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

perl参数传递的三种方法

1.使用perl自带的Long.pm模块,
use Getopt::Long;        
Getopt::Long::Getoptions(
            'c=s'  => \$community,  //c是传递的参数标识符,s代表传递的参数是字符串,参数将传递给$community这个变量
            'H=s'  => \$host_name,
            'v=i'  => \$version,    //i代表传递的参数是数字
);

2.使用perl自带的Std.pm模块
use Getopt::Std;
use vars qw($opt_H $opt_c $opt_v);
getopts('H:c:v:');

$host_name   = $opt_H if $opt_H;
$community = $opt_c if $opt_c;
$version = $opt_v if $opt_v;

3.自己写的脚本 while (defined($arg = shift)){       if ($arg eq "-H"){            $host_name = shift;       }elsif ($arg eq "-C"){            $community = shift;       }elsif ($arg eq "-v"){            $version = shift;       }elsif ($arg eq "-h"){            &print_help;       }else {            next;       } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐