未初始化的串联值
问题描述:
我在本论坛中已经详细讨论过“未初始化的串联值”错误,并且通常指的是未定义的变量。未初始化的串联值
但是,作为一个新手,我在下面的代码中存在“为什么”这个问题。
错误指的是变量$ sb和$ filesize。
任何洞察力,非常感谢。
谢谢!
#!/usr/bin/perl
use strict;
use warnings;
use File::stat;
#The directory where you store the filings
my $dir="/Volumes/EDGAR1/Edgar/Edgar2/10K/2009";
opendir(DIR, $dir) or die $!;
while (my $file = readdir(DIR)) {
# Use a regular expression to ignore files beginning with a period
next if ($file =~ m/^\./);
#my $form_type=substr($line,62,12);
#my $cik=substr($line,74,10);
#my $file_date=substr($line,86,10);
#Note that for file date, we need to get rid of
#the - with the following regular expression.
#month-day-year and some years there is not.
#This regular expression
#my $file_date=~s/\-//g;
my $filesize = -s "$file";
my $sb = (stat($file))[7];
print "$file,$sb,$filesize\n";
}
closedir(DIR);
exit 0;
答
您使用的是File::stat
模块。该模块实现了一个覆盖Perl内置的stat
功能。它会返回一个对象而不是一个列表。所以这个:
my $sb = (stat($file))[7];
导致$sb
是未定义的,因为只有在清单1中的对象。你所做的是用模块功能代替:
my $sb = stat($file)->size();