in reply to Sorting Hash: Sort Criteria Moved Into Eval

On this:

C:\>perl -v This is perl, v5.8.4 built for MSWin32-x86-multi-thread

both lists are sorted identically using your exact code.

Using:

$ perl -v This is perl, v5.6.1 built for i386-linux

the results are the same as yours. Changing the eval'd version to:

# sort criteria eval-ed: wacky results my $sortCriteria = sub { $hr->{$b}->{"number"} <=> $hr->{$a}->{"numb +er"};}; # WHAT AM I DOING WRONG ON THE NEXT LINE? @sortedKeys = sort { &{$sortCriteria} } keys %$hr; print "\n\nsort criteria eval-ed\n"; foreach my $sortedKey(@sortedKeys){ print $hr->{$sortedKey}->{"number"} . " " . $hr->{$sortedKey}->{'n +ame'} . "\n"; }

yields an identically sorted list, leading me to:

# sort criteria eval-ed: wacky results my $sortCriteria = '$hr->{$b}->{"number"} <=> $hr->{$a}->{"number"}; +'; # WHAT AM I DOING WRONG ON THE NEXT LINE? @sortedKeys = sort { &x($sortCriteria) } keys %$hr; print "\n\nsort criteria eval-ed\n"; foreach my $sortedKey(@sortedKeys){ print $hr->{$sortedKey}->{"number"} . " " . $hr->{$sortedKey}->{'n +ame'} . "\n"; } sub x { eval shift; }

yielding the same identically sorted list but using an easily changed string.