【问题标题】:Uninitialized value in concatenation连接中的未初始化值
【发布时间】:2014-11-23 10:40:03
【问题描述】:

我有这个论坛中详细讨论过的“未初始化的值连接”错误,通常是指未定义的变量。

但是,作为一个新手,我不知道“为什么”下面的代码中存在问题。

错误涉及变量 $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;  

【问题讨论】:

    标签: perl


    【解决方案1】:

    您正在使用File::stat 模块。这个模块实现了一个覆盖 Perl 内置的stat 功能。它返回一个对象而不是一个列表。所以这个:

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

    导致 $sb 未定义,因为列表中只有 1 个对象。您所做的是改用模块功能:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      • 1970-01-01
      相关资源
      最近更新 更多