【发布时间】:2015-03-30 03:09:20
【问题描述】:
您好,下面是我的 perl 代码:
#!/usr/bin/perl -w
no warnings;
use Env;
my $p4user = $ENV{'P4USER'};
my $current_path = $ENV{'PWD'};
print("\t Hello $p4user. You are currently in $current_path path.\n");
open($user_in,"$ARGV[0]") || die("failed to open the argument file $ARGV[0]\n");
print("\t To create a new client enter '1' |");
print("\t To use an existing client enter '2' : ... ");
my $cl_op = <>;
chop($cl_op);
if (($cl_op == 1) || ($cl_op == 2))
{
# do something common for both condition
if ($cl_op == 1)
{
# do something
}
elsif ($cl_op == 2)
{
# do something
}
}
else
{
die("\n\t Sorry. Invalid option : $cl_op\n");
}
然后脚本运行如下:
Hello biren. You are currently in /remote/vgvips18/biren/tcf_4nov path.
Sorry. Invalid option : ###################################################################
To create a new client enter '1' | To use an existing client enter '2' : ...
知道为什么脚本会这样。当我注释掉这一行时“
打开($user_in,"$ARGV[0]") || die("打开参数文件失败 $ARGV[0]\n");
",脚本运行良好。 当我在命令行上将文件作为参数传递时,任何人都可以帮助解释为什么脚本的行为。
【问题讨论】:
-
使用
die("failed to open the argument file $ARGV[0]: $!\n")获取有关打开失败原因的更多信息。也许该文件不存在或不可读? -
为什么禁用警告,为什么不使用严格?他们会指出脚本中的许多问题,并且应该始终包含在内。
标签: perl