You'll have to change theuse strict; use warnings; use Data::Dumper my %hash = ( '10857' => [ '10857', 'Test-host1', '192.168.162.124', undef, undef, undef, undef, 'Timeout while connecting to "192.168.162.124:1 +61"' ], '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_array = sort {$a->[0] <=> $b->[0] } values %hash; print Dumper \@sorted_array;
part to something like: { (do something for undef values;) $a->4 <=> $b->4 }{$a->[0] <=> $b->[0] }
The result:
ARRAY(0x404bfc18) 0 10582 1 'Test-Host3' 2 '192.168.162.95' 3 'icmppingsec' 4 117.390000 5 116.493000 6 '2014-04-01 20:23:03' 7 '' 1 ARRAY(0x40135fe0) 0 10715 1 'Test-Host2' 2 '192.168.162.146' 3 'checkPing[{HOST.IP}]' 4 108 5 108 6 '2014-04-01 20:24:01' 7 '' 2 ARRAY(0x40573600) 0 10778 1 'Test-Host3' 2 '192.168.162.144' 3 'checkPing[{HOST.IP}]' 4 392 5 359 6 '2014-04-01 20:21:12' 7 '' 3 ARRAY(0x4012a0d8) 0 10857 1 'Test-host1' 2 '192.168.162.124' 3 undef 4 undef 5 undef 6 undef 7 'Timeout while connecting to "192.168.162.124:161"'
In reply to Re: Need to sort and data structure based on values inside arrayrefs.
by Laurent_R
in thread Need to sort and data structure based on values inside arrayrefs.
by shekarkcb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |