in reply to Re: Need to sort and data structure based on values inside arrayrefs.
in thread Need to sort and data structure based on values inside arrayrefs.
Something to do for undefs: coerce to zero.
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $hashref = { '10857' => [ '10857', 'Test-host1', '192.168.162.124', undef, undef, undef, undef, 'Timeout while connecting to \"192.168.162.124:161\"', ], '10715' => [ '10715', 'Test-Host2', '192.168.162.146', 'checkPing[{HOST.IP}]', '108', '108', '2014-04-01 20:24:01', '', ], '10778' => [ '10778', 'Test-Host3', '192.168.162.144', 'checkPing[{HOST.IP}]', '392', '359', '2014-04-01 20:21:12', '', ], '10582' => [ '10582', 'Test-Host3', '192.168.162.95', 'icmppingsec', '117.390000', '116.493000', '2014-04-01 20:23:03', '', ], }; ;; my @sorted = do { no warnings 'uninitialized'; sort { $a->[4] <=> $b->[4] } values %$hashref; }; ;; dd \@sorted; " [ [ 10857, "Test-host1", "192.168.162.124", undef, undef, undef, undef, "Timeout while connecting to \"192.168.162.124:161\"", ], [ 10715, "Test-Host2", "192.168.162.146", "checkPing[{HOST.IP}]", 108, 108, "2014-04-01 20:24:01", "", ], [ 10582, "Test-Host3", "192.168.162.95", "icmppingsec", "117.390000", "116.493000", "2014-04-01 20:23:03", "", ], [ 10778, "Test-Host3", "192.168.162.144", "checkPing[{HOST.IP}]", 392, 359, "2014-04-01 20:21:12", "", ], ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Need to sort and data structure based on values inside arrayrefs.
by Laurent_R (Canon) on Apr 01, 2014 at 18:53 UTC | |
by AnomalousMonk (Archbishop) on Apr 01, 2014 at 19:24 UTC | |
by Laurent_R (Canon) on Apr 01, 2014 at 21:42 UTC | |
by AnomalousMonk (Archbishop) on Apr 02, 2014 at 17:19 UTC |