in reply to Print Max Hash

Have you tried checking what $ne really contains? In the sample you posted below, it seems to always be
$ne = 'ne';

So, there's only one key, and its value is always the maximum. Can you show what output do you expect?

Maybe you wanted $fields[15] instead of 17?

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Print Max Hash
by bartrad (Beadle) on Jan 30, 2018 at 13:00 UTC

    Hi, $ne is a multitude of different numbers that I know outputs as expected. Example is 20487273 or 111111. In my sample that I posted I removed the actual values that my input file contained as it's sensitive data and replaced with 'ne'. To be honest I could've replaced it with anything. Field 15 is just a placeholder, 17 definitely prints what I need.

      I'm trying to only print the occurrence once

      Not sure what you are trying to do. If you want to stop multiple records then just use a %seen{key} hash e.g.

      #!perl use strict; my %seen = (); while ( my $line = <DATA> ) { next if $line =~ /Insufficent|CLEARED/; if ( $line =~ /SNMP/ ) { my @f = split /\|/, $line; my $node_ip = $f[4] || 'N/A'; my $message = $f[13]; my (undef,$ne) = split /[ &]+/,$f[15]; unless ( $seen{$ne}++ ){ printf "%-15s | %9s | %s \n", $node_ip, $ne, $message; } } } __DATA__ 143599203|No|NACK|ENA||Major|20180129054027||ARM|NSA|PRM|0|DCN|Insuffi +cient SNMP security settings|HN408-CP-1E-I|3176 && 1234|||||||No|| 143599356|No|NACK|ENA|192.168.0.1|Major|20180129054037||CLR|NSA|PRM|0| +DCN|CLEARED: Network element does not respond to SNMP requests|HN4000 +e|3176 && 12345|||||||No|| 143599357|No|NACK|ENA|192.168.0.2|Major|20180129054039||CLR|NSA|PRM|0| +DCN|CLEARED: Insufficient SNMP security settings|HN4000e|3176 && 1234 +56|||||||No|| 143599999|No|NACK|ENA|192.168.0.3|Major|20180129054529||ARM|NSA|PRM|0| +DCN|Network element does not respond to SNMP requests|HN4000e|3176 && + 7890|||||||No|| 143599999|No|NACK|ENA|192.168.0.3|Major|20180129054529||ARM|NSA|PRM|0| +DCN|Network element does not respond to SNMP requests|HN4000e|3176 && + 7890|||||||No|| 143599999|No|NACK|ENA|192.168.0.3|Major|20180129054529||ARM|NSA|PRM|0| +DCN|Network element does not respond to SNMP requests|HN4000e|3176 && + 7890|||||||No||
      poj

        Hi Poj, that worked a treat thank you.

        Suppose in my printf I wanted to show the count of how many times said $ne has occurred against the single entry for that $ne, how would I do that? Thanks again!