加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl参数传递的三种方法

发布时间:2020-12-15 20:52:18 所属栏目:大数据 来源:网络整理
导读:1.使用perl自带的Long.pm模块, use Getopt::Long;???????? Getopt::Long::GetOptions( ??????????? 'c=s'? = $community,? //c是传递的参数标识符,s代表传递的参数是字符串,参数将传递给$community这个变量 ??????????? 'H=s'? = $host_name, ??????????

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; ????? } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读