Inside the loop I check if the value is defined, so I don't care where in the order the undefined one shows up in. I don't want to delete undefined ones or anything...
On 4/25/07, Chas Owens <[EMAIL PROTECTED]> wrote:
On 4/25/07, yitzle <[EMAIL PROTECTED]> wrote: > Warning message: > Use of uninitialized value in numeric comparison (<=>) at ... > > Code: > foreach (sort { $dHash{$b}{'VAL} <=> $dHash{$a}{'VAL'} } keys %dHash) { > > How do I fix? Should my sort function be checking for variable > defined? What do I return on undefined? It sounds like one of your keys does not have the key 'VAL' defined or its value is undef. This may or may not be an error (which is why it is a warning message). I would loop over %dHash until I found the bad value(s) and then decided what to do from there. for my $key (sort keys %dHash) { if (not exists $dHash{$key}{VAL}) { print "$key does not have a VAL\n"; elsif (not defined $dHash{$key}{VAL}) { print "$key's VAL is undefined" } }
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/