On 08/21/2012 08:29 PM, Eduardo wrote:
On 22/08/12 00:35, Uri Guttman wrote:


my %cache = ();
foreach ( keys %$hash )
{
    my ( $naa, $nab ) = $_ =~ m|^(\d+)-(\d+)|;
    $cache{ ($naa * 100 + $nab ) } = $_;
}

that is a variant of the orcish manoever which is supported by sort::maker.

foreach ( sort { $a <=> $b } keys %cache )
{
    print "[*] $cache{$_}\n";
}

without repeating code, use a formula forcaching keys.
you only need to know the size of the sendond keys.


how would you do with Sort::Maker?

i don't have time to show an example now but it is much cleaner looking. all you need to do is code up how you extract each key from the data set and how it gets sorted (number vs string, etc.). it makes sorting into a declarative problem instead of a coding problem.

uri


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to