2014-11-23 6 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]; 

목록에서 단 1 개체가 있기 때문에 $sb가 정의되지 않은되도록합니다. 대신 모듈 기능을 사용하는 것입니다 :

my $sb = stat($file)->size(); 
관련 문제