in reply to Two sort in single Array set
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Two sort in single Array set
by Anonymous Monk on Aug 31, 2017 at 16:50 UTC | |
by johngg (Canon) on Aug 31, 2017 at 22:46 UTC |