in reply to Getting first and last element value of a hash loop
Use Time::Seconds
use Time::Seconds; my @LIST = map { [ $_->[0], $_->[1], $_->[2], $_->[3], $_->[4], $_->[5],$_->[6] + ] } sort { $a->[0] cmp $b->[0] || $b->[4] <=> $a->[4] || $a->[1] cmp $b-> +[1] || $a->[2] cmp $b->[2] || $a->[3] cmp $b->[3] } map { my $group = $_; map { my $host = $_; map { my $service = $_; map { my $state = $_; my $count = keys %{$ERROR1{$group}->{$host}->{ +$service}->{$state}}; my $ts1 = (sort (keys %{$ERROR1{$group}->{$hos +t}->{$service}->{$state}}))[0]; my $ts2 = (sort(keys %{$ERROR1{$group}->{$host +}->{$service}->{$state}}))[-1]; [ $group, $host, $service, $state, $count, Tim +e::Seconds->new($ts2-$ts1)->pretty() ] } keys %{$ERROR1{$group}->{$host}->{$_}} } keys %{$ERROR1{$group}->{$_}} } keys %{$ERROR1{$_}} } keys %ERROR1; for $_ (@LIST){ print join("\t", @{$_}) ."\n"; }
Oracle server1 FILESYSTEM ALERT WARNING 85% FULL 8 + 23 hours, 30 minutes, 4 seconds Oracle server2 FILESYSTEM ALERT WARNING 85% FULL 5 + 21 hours, 59 minutes, 59 seconds Oracle server1 BACKUP ALERT DAILY 1 0 seconds
And what the others are trying to say is that:
my ($ts1,$ts2) = (sort (keys %{$ERROR1{$group}->{$host}->{$service}->{ +$state}}))[0,-1];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting first and last element value of a hash loop
by FreeBeerReekingMonk (Deacon) on Jun 05, 2015 at 22:29 UTC | |
by techworkpc (Initiate) on Jun 05, 2015 at 23:01 UTC |