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

目前无法理解的命令行处理

发布时间:2020-12-16 00:38:01 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/env perl use warnings; use strict; use Getopt::Long qw(:config gnu_getopt); my %options = ( ??????? 'help' = +{spec = 'help|?|h',value = undef },??????? # default output is "short" options ??????? 'long' = +{spec = 'long-options

#!/usr/bin/env perl use warnings; use strict; use Getopt::Long qw(:config gnu_getopt); my %options = ( ??????? 'help' => +{spec => 'help|?|h',value => undef },??????? # default output is "short" options ??????? 'long' => +{spec => 'long-options|l!',??????? # count of options printed each line ??????? 'width' => +{spec => 'width|w=i',value => 4},??????? # verbose mode,report each option hit as scanning ??????? 'verbose' => +{spec => 'verbose|v!',value => 0},??????? # dummy option ??????? 'option1' => +{spec => 'option1|o=s',value => undef},); GetOptions( ??????? map {; ??????????????? $options{$_}{spec} => ??????????????????????? (ref($options{$_}{value}) ? $options{$_}{value} : $options{$_}{value}); ??????? } keys(%options) ); if ($options{help}{value}) { usage(); } ## 这里是要特殊处理的地方 if (defined($options{option1}{value})) { ??????? my @items = split 's*,s*',$options{option1}{value}; ??????? $options{option1}{value} = @items; } ### option dumping print "Your options:n"; foreach (keys(%options)) { ??????? printf "? %s: %sn",$_,argument_value($options{$_}{value}); } exit 0; sub argument_value { ??????? my ($val) = @_; ??????? unless (defined($val)) { ??????????????? return '<undef>'; ??????? } ??????? if (ref($val)) { ??????????????? if (ref($val) eq 'ARRAY') { ??????????????????????? return "[" . join(" ",@$val) . "]"; ??????????????? } else { ## ignore other types ??????????????????????? return "<UNKNOWN>"; ??????????????? } ??????? } else { ??????????????? # scalar ??????????????? return $val; ??????? } } sub usage { ??????? (my $PROG = $0) =~ s/^.*///; ??????? print <<EOF; USAGE ??????? $PROG OPTIONS OPTIONS: ?????????? -l,--long??????????????? Long options switch ?????????? -w,--width=N???????????? Number of options to print each line ?????????? -h,--help??????????????? This help screen COPYRIGHT ?????????? (C) 2010 XXX XXXXXXX,<XXX@gmail.com> EOF ??????? exit 1; }

(编辑:李大同)

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

    推荐文章
      热点阅读