Hey, have what is probably a simple question, but I'm struggling a bit and I've checked what I know to check. I have a hash to sort by value, and I'm getting "Use of uninitialized value in string comparison (cmp) at blahblah line 66." when I sort it. But I've checked and don't seem to have any empty values. Hopefully I don't make a syntax error, I have to type it because it's in a secure system so I can't copy/paste and I had to anonymize function names and hash names and stuff. It does run, and it sorts the hashes fine.
Code:
#!/usr/bin/perl
use Win32;
use strict;
use warnings;
use v5.10.10;
use Data::Dumper;
user constant {
DEBUG => 1,
}
my %hash;
my $counter;
#hash has stuff put in it here
$counter = &compare_hash(\%hash);
sub compare_hash{
my $hashRef = shift;
my $hash = %$hashRef;
my $counter = 0;
print Dumper(\%hash); #searching for undef or blank ('') values in
+ the dump output comes up empty
print "$_ has undef as value\n" for grep {not defined $hash{$_}} k
+eys %hash #this comes up empty, thanks to Corion for the
#suggestion
foreach my $key (sort { $hash{$a} cmp $hash{$b} } keys %hash){ #th
+is is line 66
#do something
#print and check and stuff on $hash{$key}
++$counter;
}
return $counter;
}
Thanks in advance.