is there way i can use s/^\s+|\s+$//g only once for all the variables
s/^\s+|\s+$//g for $severity, $ticketnum, $timereceived, ...;
Doesn't apply to $remedyqueue though, one way to make that a little bit more idiomatic might be:
my $remedyqueue = [ map { $_->string_value=~s/^\s+|\s+$//gr } $xp->find("./custom_attribute_list/custom_attribute[normalize-space( +name)='SLB_RemedyQueue']/value", $node) ->get_nodelist ];
Or, for Perl versions before 5.14: map { (my $x=$_->string_value)=~s/^\s+|\s+$//g; $x }
if i use sprintf("%.0f h", $diff_hours); gives me err in sorting statement Argument "2158 h" isn't numeric
You didn't implement the suggestion I showed, instead you're attempting to sort by the field event_age, which does contain strings like "2158 h", which are not plain numbers and therefore can't be compared by the numeric comparison operator <=> <update> cause warnings when you try to use the numeric comparison operator <=> to compare them. </update> I would suggest you implement the suggestion I showed, and if you don't want that field to show up in the JSON, then after the sorting you could do delete $_->{timereceived} for @records;. (While you could theoretically also remove the " h" from the event_age field and then sort that numerically, note that since you've rounded the value, I think you might find that the sorting will be unreliable for events that happened in the same hour.) Also, note that you should move the sort entirely outside the loop, doing it on every iteration is not necessary.
In reply to Re^5: Sort the hash array (updated)
by haukex
in thread Sort the hash array
by snehit.ar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |