从下面的代码中,我收到错误
Use of uninitialized value $fileName in concatenation <.> or string at ... line 8.
我也得到错误
Can't open from: No such file or directory at ... line 8.
这是家庭作业参考的示例代码。我想要理解它。
use strict;
use warnings;
my $dayLength = $ARGV[0];
my $byteLength = $ARGV[1];
my $fileName = $ARGV[2];
open INPUT, "< $fileName" or die "Can't open from: $!";
my $takeIn = <INPUT>;
print "$takeIn\n";
my @files = split / /, $takeIn;
print "@files\n";
foreach my $file (@files){
if(-M $file > $dayLength && -s $file > $byteLength){
print "\n::::::::$file::::::::\n";
open INPUT, "< $file" or die "Can't open from: $!";
my $i = <INPUT>;
while($i = <INPUT>){
print $i;}
}}
答案 0 :(得分:1)
正如Hunter所提到的那样,似乎没有第三个参数,并且没有设置$ fileName。
尝试在调用open()之前添加它,以确保用户提供文件名。
if (!defined($filename) or length($filename) == 0))
{
die "filename argument is required";
}