[Israel.pm] how to sorting the hash elements dynamically
rami doqa
rod082 at yahoo.com
Wed Jul 19 08:19:59 EEST 2006
Hello Perl group:
I am interesting in how can I do a dynamic sorting for
the hash elements. ex:
# code example
$result->[1] = {
'key_1' => [14,20,37,46,..];
'key_n' => [10,42,15,60,..];
};
# Sometimes I want to sort the inner hash in ASC and
sometimes DESC way
# SO I am trying to do the following but i know an
error will occur..
if (# something...)
{
$syntax = "{$result->[1]{$a}[3] <=>
$result->[1]{$b}[3]}"; # ASC
}
else
{
$syntax = "{$result->[1]{$b}[3] <=>
$result->[1]{$a}[3]}"; # DESC
}
foreach my $key(sort $syntax keys (%{$result->[1]}) )
{
#do the DESC or ASC iteration...
}
my regards = "many";
print "Rami Dakka";
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Perl
mailing list