我的程序需要一个命令行参数,我想用它来改变我的Perl脚本的工作目录。如何从命令行参数插入一个变量到字符串中?
use strict;
use warnings;
use Getopt::Std;
use Cwd 'chir';
my %opts=();
getopts('a:v:l:', \%opts);
my $application = $opts{a};
my $version = $opts{v};
my $location = $opts{l};
print "$application, $version, $location\n";
if($application eq 'abc') {
#print "you came here\n";
chdir "/viewstore/ccwww/dst_${application}_${version}/abc/${location}";
print $ENV{PWD};
print "you came here\n";
}
我以前试过用chdir '/var/tmp/dst_$application/$version/$location';
,但那也没用。
该代码的当前版本提供此警告。
全局符号“$ application_”需要在./test.pl第20行显式包名。由于编译错误,执行./test.pl时中止。
20行是chdir
。
我已经尝试使用 – mahesh
使用Getopt :: Std; my%opts =(); getopts('a:v:l:\%opts); my $ application = $ opts {a}; my $ version = $ opts {v}; my $ location = $ opts {l}; if($ application eq'abc') { chdir'/ var/tmp/dst_ $ application/$ version/$ location'; } – mahesh
我在dst_ $应用程序附近出现异常,因为集中错误 – mahesh