in reply to Need to sort and data structure based on values inside arrayrefs.

Hi, sorting on the first field of the arrays instead of the 5th one, because you did not specify what to do with undef values (i.e. how to sort them):
use 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;
You'll have to change the
{$a->[0] <=> $b->[0] }
part to something like: { (do something for undef values;) $a->4 <=> $b->4 }

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"'

Replies are listed 'Best First'.
Re^2: Need to sort and data structure based on values inside arrayrefs.
by AnomalousMonk (Archbishop) on Apr 01, 2014 at 18:04 UTC
      Yes, this is one way to do it. I just did not want to decide for the OP what to do for undef, empty strings and other such special cases where it is difficult to figure out how to sort them without knowing the functional context. I'll gladly update my proposal when (and if) the OP gives additional information.

        I only wanted to suggest one way, not the only way. :)