Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Keep It Simple, Stupid
 
PerlMonks  

Use of uninitialized value in numeric comparison (<=>) error

by Win (Novice)
on Apr 12, 2006 at 08:52 UTC ( [id://542817]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Win has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

What sort of reasons could there be for the following error message?
Use of uninitialized value in numeric comparison (<=>) at Permanent.pl + line 54, <DATA> line 164. my @sorted_files = map { $_->[0] } # Error message applies here (line 54) sort { $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] } map { [ $_, [stat]->[10], [stat]->[9] ] } @files;

Replies are listed 'Best First'.
Re: Use of uninitialized value in numeric comparison (<=>) error
by McDarren (Abbot) on Apr 12, 2006 at 09:06 UTC
    #!/usr/bin/perl -w use strict; use Data::Dumper::Simple; # Your code goes here print Dumper(@files);
    I'd say that there is a very good chance that the output of that will give you your answer.
Re: Use of uninitialized value in numeric comparison (<=>) error
by davidrw (Prior) on Apr 12, 2006 at 09:07 UTC
    can you use Data::Dumper to see which is the offending file? I guess it means that there's a file where the mtime or ctime is empty... (Update {after reading McDarren's reply} Probably see that one of the elements in @files is undef OR one of the elements in @files is a file that does not exist/can't be stat'd)
    use Data::Dumper; print Dumper [ map { [ $_, [stat]->[10], [stat]->[9] ] } @files ];
    Also note that while it said "line 54", lines 54,55,56 (which has the <=>),57 are all the same statement.
      $VAR1 = [ [ 'Run_in_background_P.pl', undef, undef ], [ 'Run_in_background_Q.pl', undef, undef ] ];
      So why won't the network drive allow perl to access these attributes of the files?
        Are those two files in the current directory (the directory that the script is being run from -- see Cwd to print it out)? If no, it's not going to find them and you'll need to specify a (relative or absolute) path.
        -f || die "'$_' does not exist" for @files;
Re: Use of uninitialized value in numeric comparison (<=>) error
by japhy (Canon) on Apr 12, 2006 at 09:25 UTC
    In addition, I would suggest changing [ $_, [stat]->[10], [stat]->[9] ] to [$_, (stat)[10,9]], as it a) saves a call to stat(), and b) uses a list slice rather than two anonymous array refs.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://542817]
Approved by Corion
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.