Use of uninitialized value in numeric eq (==)

B

Ben Tisdall

Hi,

whilst I'm still trying to get my head round the debugger, any pointers
as to why the script fragment below causes one or more of the following
warnings would be most appreciated!

Use of uninitialized value in numeric eq (==) at
/Users/bentis/bin/find_dupes.pl line 12.


#!/usr/bin/perl -w
use strict;
use File::Find;
use File::Compare;
my ($infile,$i,@allfiles,$basefile,$cmpfile,$matched);
find(\&wanted, @ARGV);
sub wanted {
$infile = $File::Find::name;
{
last if (/^\~.*\.tmp/i);
last if (/^\..*/);
last if ((stat($infile))[7] == 0);
last if (-d $infile);
push (@allfiles,$infile);
}
}
....

Best,
 
P

Paul Lalli

Ben said:
whilst I'm still trying to get my head round the debugger, any pointers
as to why the script fragment below causes one or more of the following
warnings would be most appreciated!

Use of uninitialized value in numeric eq (==) at
/Users/bentis/bin/find_dupes.pl line 12.


#!/usr/bin/perl -w
use strict;
use File::Find;
use File::Compare;
my ($infile,$i,@allfiles,$basefile,$cmpfile,$matched);
find(\&wanted, @ARGV);
sub wanted {
$infile = $File::Find::name;
{
last if (/^\~.*\.tmp/i);
last if (/^\..*/);
last if ((stat($infile))[7] == 0);
last if (-d $infile);
push (@allfiles,$infile);
}
}

Does that warning appear for *every* file that find() finds, or only
certain ones? It is basically saying that the stat of $infile returned
undef for the size. I'm not sure why that would ever happen, except
for a file that does not exist. But that shouldn't happen, because
$infile is set to whatever file/directory File::Find is currently
looking at. Is this happening on a dynamically changing structure,
where a file could be there one instant and gone the next? Otherwise,
add some debugging info to the wanted() subroutine, to print out the
current file. Then see if there's something "special" about that file
on your file system if it produces the warning...

Sorry I can't be of more help,
Paul Lalli
 
R

Rod MacBan

Try performing the test

last if (-d $infile);

before

last if ((stat($infile))[7] == 0);

Rod.
 
B

Ben Tisdall

Rod said:
Try performing the test

last if (-d $infile);

before

last if ((stat($infile))[7] == 0);

Rod.
Thanks Paul & Rod, it turns out that symlinks were causing stat() to
return undef, so the fix was to make the first test:

last unless (-f $infile);

Best,
 
A

Ayaz Ahmed Khan

"Ben Tisdall" typed:
Thanks Paul & Rod, it turns out that symlinks were causing stat() to
return undef, so the fix was to make the first test:

last unless (-f $infile);

Or, use `perldoc -f lstat` instead.
 
A

anno4000

Ben Tisdall said:
Rod said:
Try performing the test

last if (-d $infile);

before

last if ((stat($infile))[7] == 0);

Rod.
Thanks Paul & Rod, it turns out that symlinks were causing stat() to
return undef, so the fix was to make the first test:

last unless (-f $infile);

stat() works fine with valid symlinks. It's only symlinks whose
target doesn't exist that return undefined values, so your fix
throws away valid results.

Also, instead of the cumbersome

((stat($infile))[7]

use

-s $file

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top