I have a program which, among other things, reads archived files containg the output of "show diagbus" on Cisco routers. The relevant strings I'm matching in my regex are:
L3 Engine: 0 - OC12 (622 Mbps)
L3 Engine: 1 - OC12 (622 Mbps)
L3 Engine: 2 - OC12 (622 Mbps)
L3 Engine: 4 - OC12 (622 Mbps)
Here's a code snippet:
%router_of_interest = (router1 => "1",
router2 => "1",
router3 => "1",
router4 => "1"
);
while ($file = readdir(DIA)) {
if ($file =~ /(.*)\.bbnplanet.net/) {
$router = $1;
next unless exists $router_of_interest{$router};
open(DIAFILE,"$dir/$file") || die "Cannot open $dir/$file: $!\n";
while ($line = <DIA>) {
chomp $line;
if ($line =~ /^\s*L3 Engine: (\d+)/i){
$engine = $1;
if (grep(/$engine/,@{$HoL_engine{$router}}) != 1){
push @{$HoL_engine{$router}}, $engine;
}
}
}
if (exists $HoL_engine{$router}){
$engine{$router} = join(",",sort @{$HoL_engine{$router}});
}
else {
$engine{$router} = "NA"; #GSR IOS version too old
}
}
}
foreach $key (sort keys %engine) {
print "$key - Engine $engine{$key}\n";
}
this successfully prints:
router1 - Engine 0,2,
router2 - Engine 1,2
router3 - Engine 2
router4 - Engine NA
...etc.
Except, it won't print instances of:
router1 - Engine 0
Something about pushing one "0" and nothing else into my HoL fails. Can anyone help a poor Monk out?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.