Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Sorting HoHoA based on Length of Second Key

by Zaxo (Archbishop)
on Jul 21, 2005 at 03:10 UTC ( [id://476697]=note: print w/replies, xml ) Need Help??


in reply to Sorting HoHoA based on Length of Second Key

Can there be keys of different length in one? Can there be a different number of keys?

I'll write this to sort by mean key length. Let's just assign an array to the sorted keys so we don't have to worry about the print loop. A Schwartzian Transform seems like a good idea for this.

my @by_mean = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [$_, length(join '', keys %{$HoHoA{$_}})/keys(%{$HoHoA{$_}})] } keys %HoHoA;
The ST lets you do the real calculation once per element, instead of repetitively in the sort comparisons.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Sorting HoHoA based on Length of Second Key
by Anonymous Monk on Jul 21, 2005 at 03:15 UTC
    Dear Mr Zaxo,
    As for your questions:
    Can there be keys of different length in one?
    NO.
    Can there be a different number of keys?
    YES.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://476697]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found