Reputation: 21
I have the "uninitialized value in concatenation" error that is thoroughly discussed in this forum, and generally refers to an undefined variable.
However, as a newbie, I'm short on "why" the problem exists in the code below.
The error refers to the variables $sb and $filesize.
Any insight is greatly appreciated.
Thank you!!!
#!/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;
Upvotes: 2
Views: 456
Reputation: 67900
You are using the File::stat
module. This module implements a stat
functionality that overrides Perl's built-in. And it returns an object instead of a list. So this:
my $sb = (stat($file))[7];
Causes $sb
to be undefined, because there is only 1 object in the list. What you do is use the modules functions instead:
my $sb = stat($file)->size();
Upvotes: 5