Tuna has asked for the wisdom of the Perl Monks concerning the following question:
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:
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?
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:
this successfully prints:%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"; }
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Puzzling Hash of Arrays problem
by athomason (Curate) on Apr 21, 2001 at 03:10 UTC | |
by Tuna (Friar) on Apr 21, 2001 at 03:20 UTC | |
Re: Puzzling Hash of Arrays problem
by jeroenes (Priest) on Apr 21, 2001 at 02:35 UTC | |
Re: Puzzling Hash of Arrays problem
by cLive ;-) (Prior) on Apr 21, 2001 at 02:35 UTC |
Back to
Seekers of Perl Wisdom