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

why does this code fail with stat?

Thread Next
From:
Harry Putnam
Date:
April 21, 2010 16:30
Subject:
why does this code fail with stat?
Message ID:
87fx2omlif.fsf@newsguy.com
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?

#!/usr/local/bin/perl

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";
find(
  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";
    }
  },
   $dir2
);

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

output
./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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About