bartrad:
Take a look at what the code in your while loop would do for each line of code:
- Checks: Running 'show port | match "Up Yes" | count'
OK, it matches /show port/, so it would skip rest of the body of the while loop.
- Count: 23 lines
It doesn't match /show port/, so it goes to the next line in the loop.
It matches /Count:\s+(\d+)/, so it would add the value to $checks{port}{$stage}
It doesn't match /show router interface/, so it goes to the next line in the loop.
It matches /Count:\s+(\d+)/, so it would add place the value to in $checks{l3}{$stage}
There's nothing else in the loop to do...
- Checks: Running 'show router interface | match "Up " | count'
It doesn't match /show port/, so it goes to the next line in the loop.
It doesn't match /Count:\s+(\d+)/, so it ignores the body of the if statement.
It matches /show router interface/, so it would skip the rest of the body of the while loop.
- Count: 4 lines
It doesn't match /show port/, so it goes to the next line in the loop.
It matches /Count:\s+(\d+)/, so it would add the value to $checks{port}{$stage}
It doesn't match /show router interface/, so it goes to the next line in the loop.
It matches /Count:\s+(\d+)/, so it would add place the value to in $checks{l3}{$stage}
There's nothing else in the loop to do...
So it looks like you're expecting 'next' to mean "read the next line" instead of "ignore the rest of the loop".
I expect you probably want something like:
while (my $line = <INPUT>) {
my item = "UNKNOWN";
if ($line =~ /show port/) { $item = "port"; }
if ($line =~ /show router interface/) { $item = "l3"; }
if ($line =~ /Count:\s+(\d+)/) { $checks{$item}{$stage} = $1; }
}
Update: Pressed "create" just a bit too soon!
Update: As AnomalousMonk mentions, it's not adding the count value.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.