Home  |  Linux  | Mysql  | PHP  | XML
From:Jim Gibson Date:Thu Jul  2 19:24:44 2009
Subject:Re: sorting anonymous arrays inside arrays
On 7/2/09 Thu Jul 2, 2009 12:12 PM, "daem0nb0y@yahoo.com"
<daem0nb0y@yahoo.com> scribbled:

>
> Hi,
>
> If I have a loop that for each run creates
>
> while (<FILE>){
> }
>
>
> Normally, if I only want to sort $myhash through it's values, I would do
> something like:
>
> foreach (sort { $a <=> $b } keys %myhash){
>
> print "$myhash{$_}\n";
>
> }

That prints the values of %myhash sorted by key. Since the values of %myhash
are references to anonymous hashes, that will not produce anything very
interesting.

> what if i want to sort the anonymous hash $myhash{$mykey}-> through it's
> value. In my first loop above, each key of %myhash has a value of an anonymous
> hash. The key for this anonymous hash is called 'subkey'. the value of course
> is $value. I want to sort this anonymous hash by $value.
>
> Any idea how to do that?

foreach (
sort { $myhash{$a}->{subkey} <=> $myhash{$b}->{subkey} }
keys %myhash
) {
print "$myhash{$_}->{subkey}\n";
}



Navigate in group perl.beginners at sever nntp.perl.org
Previous Next


Your recent visits
Re: Substitution question
Re: sequential value check
Re: Basic Perl Questions
Re: piddle in hash
piddle in hash



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants