【发布时间】:2017-04-25 20:46:57
【问题描述】:
我有一个简单的脚本:
our $height = 40;
our $width = 40;
BEGIN {
GetOptions( 'help' => \$help,
'x=i' => \$width,
'y=i' => \$height) or die "No args.";
if($help) {
print "Some help";
exit 0;
}
print $width."\n"; #it is 10 when call with script.pl -x 10 -y 10
print $height."\n"; #it is 10 when call with script.pl -x 10 -y 10
#some other code which check installed modules
eval 'use Term::Size::Any qw( chars pixels )';
if ( $@ ) {
if ( $@ =~ /Cant locate (\S+)/ ) {
warn "No modules";
exit 2;
}
}
}
print $width."\n"; #but here is still 40 not 10
print $height."\n";#but here is still 40 not 10
我用 2 个参数(x 和 y)调用这个脚本,例如:script.pl -x 10 -y 10。但是给定的值没有保存在变量 $width 和 $height 中。我想通过给出参数来改变这个变量。如何复制给定值或将它们保存到$width 和$height?有可能吗?
已编辑 - 我在此示例中添加了一些代码
【问题讨论】: