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
In reply to Re: Using Data::Dumpers Sortkeys subroutine
by nysus
in thread Using Data::Dumpers Sortkeys subroutine
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |