Hi all, after some advice. I'm opening a file and reading through it and look for some key values after the "Count:" text, but my next if's don't seem to be working properly (as they're probably not doing what I think they're doing) and instead it seems to be ignoring the next ifs and just picking up every occurrence of "Count:"

The input file

Checks: Running 'show port | match "Up Yes" | count' Count: 23 lines Checks: Running 'show router interface | match "Up " | count' Count: 4 lines

My Code

open( INPUT, "$folder/$file" ) or die("Could not open $file file"); while ( my $line = <INPUT> ) { next if ( $line =~ m/show port/ ); if ( $line =~ m/Count:\s+(\d+)/ ) { $checks{port}{$stage} = $1; } next if ( $line =~ m/show router interface/ ); if ( $line =~ m/Count:\s+(\d+)/ ) { $checks{l3}{$stage} = $1; } }

Printing out $checks{port}{$stage} shows:

23 4

When it should only show 23 for $checks{port}{$stage} and 4 for $checks{l3}{$stage}...

And a Dumper

$VAR1 = { 'card' => { 'post' => '28615', 'pre' => '28615' }, 'l3' => { 'post' => '28615', 'pre' => '28615' }, 'subs' => { 'post' => '2', 'pre' => '2' }, 'bfd' => { 'post' => 0, 'pre' => 0 }, 'binding' => { 'post' => '28615', 'pre' => '28615' }, 'ospf' => { 'post' => '2', 'pre' => '2' }, 'port' => { 'post' => '28615', 'pre' => '28615' }, 'ldp' => { 'post' => '14', 'pre' => '14' } };

Note, there's other occurrences of "Count" it's picking up but I only included two from the data source to keep things short. Any help is greatly appreciated.


In reply to Iterating and pattern matching on input file by bartrad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.