我正在尝试使用Getopt :: Long模块打开输入文件作为参数
这是我脚本的开始
#! /usr/bin/perl -s
use strict;
use warnings;
use Data::Dumper;
local $Data::Dumper::Useqq = 1;
use Getopt::Long qw(GetOptions);;
my $input='';
GetOptions('input|in=s' => \$input);
open(my $table1,'<', $input) or die "$! - [$input]"; #input file
这就是我启动脚本的方式
$ script.pl -in /path/to/file.txt
我得到的输出:
没有这样的文件或目录-script.pl第13行的[]。
第13行是的行open(...
。
脚本中有错误吗?
您正在使用-s
Shel行中的Perl的内置选项解析。在这样的命令中script.pl -in /path/to/file.txt
,使perl将变量设置$in
为1并@ARGV
在Getopt::Long
看到它之前从中删除相应的条目
只需-s
从shebang行中删除,一切都将为您工作
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句