in reply to Complex hash sorting

You might as well make the hash values refer to an array of the data,

# $hash{$_} = [ split '||', $hash{$_} ] for keys %hash; $hash{$_} = [ split /\|\|/, $hash{$_} ] for keys %hash;
You can now sort the keys any way you like by
my @by_zip = sort {$hash($a}[-1] <=> $hash{$b}[-1] } keys %hash; my @by_age = sort {$hash($a}[0] <=> $hash{$b}[0] } keys %hash; my @by_surname = sort { substr($a, rindex($a,' ')) cmp substr($b, rindex($b,' ')) } keys %hash;
Notice the difference in comparison operator between numeric and dictionary data.

Update: japhy++ is correct. Repaired without obscuring the damage.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Complex hash sorting
by japhy (Canon) on Feb 01, 2004 at 03:34 UTC
    Your '||' regex needs to be '\|\|'. And, as far as my preference goes, I'd do: $_ = [ split '\|\|' ] for values %hash;
    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;