Perl Getopt ::长相关问题 – 互斥命令行参数
发布时间:2020-12-15 23:21:29 所属栏目:大数据 来源:网络整理
导读:我的perl脚本中有以下代码: my $directory;my @files;my $help;my $man;my $verbose; undef $directory;undef @files;undef $help;undef $man;undef $verbose;GetOptions( "dir=s" = $directory,# optional variable with default value (false) "files=s"
我的perl脚本中有以下代码:
my $directory; my @files; my $help; my $man; my $verbose; undef $directory; undef @files; undef $help; undef $man; undef $verbose; GetOptions( "dir=s" => $directory,# optional variable with default value (false) "files=s" => @files,# optional variable that allows comma-separated # list of file names as well as multiple # occurrenceces of this option. "help|?" => $help,# optional variable with default value (false) "man" => $man,# optional variable with default value (false) "verbose" => $verbose # optional variable with default value (false) ); if (@files) { @files = split(/,/,join(',',@files)); } 处理互斥命令行参数的最佳方法是什么?在我的脚本中,我只希望用户只输入“–dir”或“–files”命令行参数,但不能同时输入两者.反正配置Getopt来执行此操作吗? 谢谢. 解决方法
我不认为Getopt :: Long有一种方法可以做到这一点,但它很容易自己实现(我假设有一个使用函数返回一个字符串,告诉用户如何调用该程序):
die usage() if defined $directory and @files; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |