2014-11-23 69 views
2

我在本論壇中已經詳細討論過「未初始化的串聯值」錯誤,並且通常指的是未定義的變量。未初始化的串聯值

但是,作爲一個新手,我在下面的代碼中存在「爲什麼」這個問題。

錯誤指的是變量$ 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; 

回答

5

您使用的是File::stat模塊。該模塊實現了一個覆蓋Perl內置的stat功能。它會返回一個對象而不是一個列表。所以這個:

my $sb = (stat($file))[7]; 

導致$sb是未定義的,因爲只有在清單1中的對象。你所做的是用模塊功能代替:

my $sb = stat($file)->size();