in reply to Using Data::Dumpers Sortkeys subroutine
It tests to see if the value of the has is a reference to the anonymous hash. If not, it sorts it numerically, otherwise it gets sorted alphabetically. What would be a more robust way of solving this?84 sub hash_sort { 85 my ($hash) = @_; 86 if (ref %$hash != 'REF') { 87 return [ 88 (sort {$a <=> $b} keys %$hash) 89 ]; 90 } else { 91 return [ 92 (sort {$a cmp $b} keys %$hash) 93 ]; 94 } 95 }
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
$nysus = $PM . $MCF;
Click here if you love Perl Monks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using Data::Dumpers Sortkeys subroutine
by almut (Canon) on Nov 27, 2008 at 08:01 UTC | |
by nysus (Parson) on Nov 27, 2008 at 17:22 UTC |