Just to illustrate another way, though probably too complicated for this simple problem. You can use an array slice if you sort the array indices. I use array references since that's what the OP shows and use pack/unpack and a GRT to do the sort. Note that I uc the severity so that "critical" sorts before "OK".
my $raSortedEvents = [ @{ $raEvents }[ map { unpack q{x12N}, $_ } sort map { pack( q{A8}, uc $raEvents->[ $_ ]->{ severity } ) . ( $raEvents->[ $_ ]->{ severity } eq q{OK} ? pack( q{l>}, $raEvents->[ $_ ]->{ event_age } ) : ~ pack( q{l>}, $raEvents->[ $_ ]->{ event_age } ) ) . pack( q{N}, $_ ); } 0 .. $#{ $raEvents } ] ];
I hope this is of interest.
Cheers,
JohnGG
In reply to Re: Two sort in single Array set
by johngg
in thread Two sort in single Array set
by snehit.ar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |