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
    Ben Tisdall, Dec 19, 2006
    #1
    1. Advertising

  2. Ben Tisdall

    Paul Lalli Guest

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

  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

    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
    Ben Tisdall, Dec 19, 2006
    #4
  5. "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.
    Ayaz Ahmed Khan, Dec 19, 2006
    #5
  6. Ben Tisdall

    -berlin.de Guest

    Ben Tisdall <> 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
    -berlin.de, Dec 22, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. G Kannan
    Replies:
    1
    Views:
    1,234
    Eric J. Roode
    Oct 11, 2003
  2. Sukhbir Dhillon
    Replies:
    1
    Views:
    6,253
    Joe Smith
    Apr 5, 2004
  3. smartins68
    Replies:
    1
    Views:
    6,003
    Joe Smith
    Jun 9, 2004
  4. Liang
    Replies:
    2
    Views:
    761
    Liang
    Aug 11, 2004
  5. Replies:
    5
    Views:
    933
    X-Centric
    Jun 30, 2005
Loading...

Share This Page