Use of uninitialized value in numeric eq (==)

Discussion in 'Perl Misc' started by Ben Tisdall, Dec 19, 2006.

  1. Ben Tisdall

    Ben Tisdall Guest

    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, Dec 19, 2006
    #1
    1. Advertisements

  2. Ben Tisdall

    Paul Lalli Guest

    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
     
    Paul Lalli, Dec 19, 2006
    #2
    1. Advertisements

  3. Ben Tisdall

    Rod MacBan Guest

    Try performing the test

    last if (-d $infile);

    before

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

    Rod.
     
    Rod MacBan, Dec 19, 2006
    #3
  4. Ben Tisdall

    Ben Tisdall Guest

    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, Dec 19, 2006
    #4
  5. "Ben Tisdall" typed:
    Or, use `perldoc -f lstat` instead.
     
    Ayaz Ahmed Khan, Dec 19, 2006
    #5
  6. Ben Tisdall

    anno4000 Guest

    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
     
    anno4000, Dec 22, 2006
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.