bartrad has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm returning all values from a match for a file and incrementing a hash %total each time the same one occurs. I'm trying to only print the occurrence once by only printing the max of that hash, but it's not working. To be honest, I'm not sure what it's doing with that max value as it all appears to be the same value.
while ( my $line = <INPUT> ) { if ( $line =~ /SNMP/ ) { if ( $line !~ /Insufficient/ && $line !~ /CLEARED/ ) { my @fields = split /[&\|\/]/, $line; $fields[17] =~ s/^\s+//; #REMOVE LEADING SPACES $fields[17] =~ s/\s+$//; #REMOVE TRAILING SPACES #print Dumper \@fields; my ( $node_ip, $ne, $message ) = @fields[ 4, 17, 13 ]; #ASS +IGN FIELDS VARIABLES $total{$ne}++; if ( !$node_ip ) { #FIL +L IN EMPTY SPACES WITH SOMETHING $node_ip = "N/A"; $ne = "N/A"; $total{$ne} = 0; } my $max = max values %total; printf( "%-15s | %9s | %5s | %-55s | %9s | \n", $node_ip, $ne, + $total{$ne}, $message, $max ) # if $total{$ne} == $max; } } } close(INPUT);
Can someone offer any assistance please? I've commented out the if at the end of my printf statement for testing to see exactly what max value is returned and it is the same value regardless of what $ne is.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Print Max Hash
by choroba (Cardinal) on Jan 30, 2018 at 12:23 UTC | |
by bartrad (Beadle) on Jan 30, 2018 at 13:00 UTC | |
by poj (Abbot) on Jan 30, 2018 at 13:14 UTC | |
by bartrad (Beadle) on Jan 30, 2018 at 14:35 UTC | |
by poj (Abbot) on Jan 30, 2018 at 14:55 UTC | |
by johngg (Canon) on Jan 30, 2018 at 14:46 UTC | |
|
Re: Print Max Hash
by Marshall (Canon) on Jan 30, 2018 at 10:40 UTC | |
by bartrad (Beadle) on Jan 30, 2018 at 10:51 UTC | |
by choroba (Cardinal) on Jan 30, 2018 at 13:09 UTC | |
by Marshall (Canon) on Jan 30, 2018 at 11:06 UTC | |
by bartrad (Beadle) on Jan 30, 2018 at 11:11 UTC | |
by karlgoethebier (Abbot) on Jan 30, 2018 at 17:18 UTC |