develooper Front page | perl.beginners | Postings from April 2010

why does this code fail with stat?

Thread Next
Harry Putnam
April 21, 2010 16:30
why does this code fail with stat?
Message ID:
I've run into one of those things where I can't see why my code
fails. ... and know it has to be something obvious.

Why does the second usage of stat... fail in the find() funciton?


use strict;
use warnings;
use File::Find;

my $dir2 = './dir2';
my $fname1 = shift;
my ($lastfld) = $fname1 =~ m{^.*/([\w\d\-_]+)$};

my $size = (stat($fname1))[7];
print "$fname1 size: $size\n";
  sub {
    if ($lastfld eq $_) {
      print "<$lastfld> matches <$_>; Lets check the size:\n";
      my $size = (stat($File::Find::name))[7];
      print "$File::Find::name size: $size\n";

-------        ---------       ---=---       ---------      --------
./stat ./dir1/sub1/file

./dir1/sub1/file size: 10
<file> matches <file>; Lets check the size:
Use of uninitialized value $size in concatenation (.) or string at ./stat line 23.
./dir2/file size: 

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About