http://www.perlmonks.org?node_id=74364


in reply to Puzzling Hash of Arrays problem

Hmmm... once I puzzled my way through your unusual indentation, I noticed a few things that would make this better code.

After all that, we're left without something like this, which worked for me on manufactured data.

use strict; use warnings; my %router_of_interest = ( router1 => 1, router2 => 1 ); # .... my %engine; opendir DIA, '/'; while (my $file = readdir(DIA)) { next unless $file =~ /(.*)\.bbnplanet.net/; my $router = $1; next unless exists $router_of_interest{$router}; my %HoH_engine; open(DIAFILE, "<$file") or die "Cannot open $file: $!\n"; while (my $line = <DIAFILE>) { chomp $line; if ($line =~ /^\s*L3 Engine: (\d+)/i) { my $engine = $1; $HoH_engine{$router}{$engine} = 1; } } if (exists $HoH_engine{$router}){ $engine{$router} = join(",", sort keys %{$HoH_engine{$router}}); } else { $engine{$router} = "NA"; #GSR IOS version too old } } foreach my $key (sort keys %engine) { print "$key - Engine $engine{$key}\n"; }

Update: Still broken? Odd... when I put L3 Engine: 0 - OC12 (622 Mbps) by itself in router1.bbnplanet.net, I get the outputrouter1 - Engine 0. Could something be wrong elsewhere?

Replies are listed 'Best First'.
Re: Re: Puzzling Hash of Arrays problem
by Tuna (Friar) on Apr 21, 2001 at 03:20 UTC
    Thanks for the reply. For the sake of brevity, I omitted parts of the program, including the section where I declare my variables. Thanks to all here, I ALWAYS use strict and -w! =)

    However, your suggestions produce the exact same results as my code. ++, nonetheless!


    update: typo


    update 2: Well, I cut 'n pasted again, and lo' and behold it works!

    Thanks,

    Steve