Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Here a proof of concept: (stealing data from AppleFritter's example)

#!/usr/bin/perl use strict; use warnings; use feature qw/say/; use Data::Dump qw/pp dd/; my %data = ( "key0.1" => [ { "key1.1" => 3.3, "key1.2" => 17.8, "key1.3" => -2.4, }, { "key1.4" => 5.1, "key1.5" => 13, }, { "key1.6" => -69, "key1.7" => 127, "key1.8" => 2.718, "key1.9" => 3.3, }, ], "key0.2" => [ { "key1.10" => 3.3, "key1.11" => 2.5, }, { "key1.12" => -33, }, ], ); my %flat = (); while (my ($k0,$v0) = each %data) { my $k1=-1; for my $v1 (@$v0) { $k1++; while (my ($k2,$v2) = each %$v1) { $flat{$k0,$k1,$k2} = $v2; } } } my @sorted_keys = sort { $flat{$a} <=> $flat{$b} } keys %flat; for my $k (@sorted_keys) { my $v = $flat{$k}; say "$v \t<= \t", join ", ", split ( $; , $k ); }

Output:

-69 <= key0.1, 2, key1.6 -33 <= key0.2, 1, key1.12 -2.4 <= key0.1, 0, key1.3 2.5 <= key0.2, 0, key1.11 2.718 <= key0.1, 2, key1.8 3.3 <= key0.1, 0, key1.1 3.3 <= key0.1, 2, key1.9 3.3 <= key0.2, 0, key1.10 5.1 <= key0.1, 1, key1.4 13 <= key0.1, 1, key1.5 17.8 <= key0.1, 0, key1.2 127 <= key0.1, 2, key1.7

HTH! =)

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)


In reply to Re^2: sorting hash of array of hashes by value by LanX
in thread sorting hash of array of hashes by value by Special_K

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2021-10-26 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (91 votes). Check out past polls.

    Notices?