Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Use of uninitialized value in numeric eq (==)

Reply
Thread Tools

Use of uninitialized value in numeric eq (==)

 
 
Ben Tisdall
Guest
Posts: n/a
 
      12-19-2006
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,

--
Ben Tisdall
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      12-19-2006
Ben Tisdall wrote:
> 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

 
Reply With Quote
 
 
 
 
Rod MacBan
Guest
Posts: n/a
 
      12-19-2006

Try performing the test

last if (-d $infile);

before

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

Rod.

 
Reply With Quote
 
Ben Tisdall
Guest
Posts: n/a
 
      12-19-2006
Rod MacBan wrote:
> 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,

--
Ben Tisdall
 
Reply With Quote
 
Ayaz Ahmed Khan
Guest
Posts: n/a
 
      12-19-2006
"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.

--
Ayaz Ahmed Khan

It is impossible to defend perfectly against the attack of those who
want to die.

 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      12-22-2006
Ben Tisdall <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Rod MacBan wrote:
> > 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
int to numeric numeric(18,2) ? jobs ASP .Net 2 07-22-2007 12:32 AM
Arithmetic overflow error converting numeric to data type numeric. darrel ASP .Net 4 07-19-2007 09:57 PM
check if string contains numeric, and check string length of numeric value ief@specialfruit.be C++ 5 06-30-2005 01:08 PM
Re: Use of uninitialized value in concatenation (.) or string Error Sukhbir Dhillon Perl 1 04-05-2004 02:31 AM
Use of uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10. G Kannan Perl 1 10-11-2003 11:58 AM



Advertisments