in reply to Re: Iterating and pattern matching on input file
in thread Iterating and pattern matching on input file

Thanks for your response. Yeah, that's exactly what I want - "next line", rather than "next". I've updated the code but doesn't seem to be working?

my $item = "UNKNOWN"; if ( $line =~ m/show port/ ) { $item = + "port"; } if ( $line =~ m/show router interface/ ) { $item = + "l3"; } if ( $line =~ m/Count:\s+(\d+)/ ) { $checks{$item}{$stage} = + $1; }
$VAR1 = { 'subs' => { 'post' => '2', 'pre' => '2' }, 'bfd' => { 'post' => 0, 'pre' => 0 }, 'ospf' => { 'post' => '2', 'pre' => '2' }, 'UNKNOWN' => { 'post' => '28615', 'pre' => '28615' }, 'ldp' => { 'post' => '14', 'pre' => '14' } };

Am I missing something?

Replies are listed 'Best First'.
Re^3: Iterating and pattern matching on input file
by roboticus (Chancellor) on Jul 31, 2018 at 23:50 UTC

    bartrad:

    I can't tell what's wrong as you don't show the input data, nor is there enough code to see what's happening.

    From what you're showing me, I'd guess that there's a spelling error in there and the items you're trying to capture are treated as UNKNOWN.

    You might try showing a bit more of your code and/or your test data.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re^3: Iterating and pattern matching on input file
by AnomalousMonk (Archbishop) on Jul 31, 2018 at 23:57 UTC