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?

In reply to Puzzling Hash of Arrays problem by Tuna

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.