http://www.perlmonks.org?node_id=1047529

viffer has asked for the wisdom of the Perl Monks concerning the following question:

Hi all I am trying to obtain a time stamp using File::stat.

I am obtaining values in the array, but when I try and access individual fields they return undef.

my $filename = "$directory$file"; my @array=stat($filename);
returns
DB<2> x @array 0 File::stat=ARRAY(0x3055e8e4) 0 1638407 1 281494 2 33188 3 1 4 500 5 1231 6 0 7 97900 8 1375400720 9 1375371182 10 1375371182 11 4096 12 192
yet when I try and access a value in the array, via
my $time = $array[9];
it returns undef.

I have since found that

my $time = $array[0][9]
does indeed return the value "1375371182"

Similarly when using

my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime +,$blksize,$blocks) = stat($filename);
stat returns undef in all fields.

I kind of get that it's returned a two dimensional array, but I don't really follow why the code above doesn't appear to work?

hellllp! :)

Thanks Kev

Replies are listed 'Best First'.
Re: Stat - returning undef values (NOT)
by Anonymous Monk on Aug 02, 2013 at 03:37 UTC
    You're not dealing with stat, you're dealing with File::stat, their usages are different
      Thanks - deleted the use File::stat line and all works.