In article <008301c2cbbd$15c27c40$8afea8c0@pkraus>,
 [EMAIL PROTECTED] (Paul Kraus) writes:
>This is straight from the camel pg 277.
>Unless I misunderstand this then the items with 3 elements should be at
>the top not in the middle.
>What am I doing wrong? 
>
>Can someone break down what the sort statement in this situation is
>doing.
>References are still confusing the hell out of me.
>
>My code
>-------
>foreach (sort { @{$count{$b}}<=>{$count{$a}}}keys %count){
>      if ($#{$count{$_}}>1){
>       print "$_ = @{$count{$_}}\n";
>      }
>    }

Others have pointed out why the order is wrong.  I'll explain it as though
the @ was put back:

foreach (sort { @{$count{$b}}<=>@{$count{$a}}}keys %count)

A bit of white space will help:

foreach (sort { @{ $count{$b} } <=> @{ $count{$a} } } keys %count)

This tells us that the values of the hash %count are references to arrays,
because we are taking successive pairs of keys of that hash ($a and $b),
getting their corresponding values, and dereferencing each one as though
it were an arrayref.  Any other content will cause an error (aside from
undef - look up autovivification).

<=> puts its arguments in scalar context, hence we are comparing number
of elements in each array, and since $b is on the left hand side we get
descending order.

I'll leave the rest to your further reading.

-- 
Peter Scott
http://www.perldebugged.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to