Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Sorting Multilevel Hashes

by hdb (Monsignor)
on Apr 25, 2014 at 06:29 UTC ( #1083733=note: print w/replies, xml ) Need Help??

in reply to Sorting Multilevel Hashes

If you only want to print the sorted rows into another file, then IMHO it is easier to read the file into an array of arrays and sort them then.

use strict; use warnings; my $header = <DATA>; my @rows = map { join "\t", @$_ } sort { $a->[1] cmp $b->[1] || $a->[2] cmp $b->[2] || $a->[3] cmp $b->[3] || $a->[4] <=> $b->[4] } map {[ split /\s+/ ]} <DATA>; print $header; print "$_\n" for @rows; __DATA__ pin Name related_pin time_type rise_fall delay DQ5_RX_CLK M2CLKP c_rise rise_transition 0.014446 DQ2_RX_CLK M2CLKP c_rise rise_transition 0.014464 DQ0_RX_CLK M2CLKP c_rise rise_transition 0.014452 DQ3_RX_CLK M2CLKP c_rise rise_transition 0.014452 DQ7_RX_CLK M2CLKP c_rise rise_transition 0.014430 DQ4_RX_CLK M2CLKP c_rise rise_transition 0.014446 DQ8_RX_CLK INT_CLK c_fall fall_transition 0.199360 DQ6_RX_CLK INT_CLK c_fall fall_transition 0.199322 DQ1_RX_CLK INT_CLK c_fall fall_transition 0.199500 DQ5_RX_CLK INT_CLK c_fall fall_transition 0.199248 DQ2_RX_CLK INT_CLK c_fall fall_transition 0.199368

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1083733]
and !@monks...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-05-21 22:52 GMT
Find Nodes?
    Voting Booth?