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.