Tuna has asked for the wisdom of the Perl Monks concerning the following question:

Thanks to all who have helped me out with this one; my first "real" program!
Code snippet:
foreach $element_priv(@priv) { open FILE, "$as_dir/$element_priv" or warn ("Can't open $as_dir +/$element_priv: $!\n"), next; while ($compare_lines = <FILE>) { chomp $compare_lines; next if ($compare_lines =~ /unknown|shutdown/); ($as,$as_name,$neighbor,$router,$interface,$address,$interf +ace_name,$ifindex,$vpi,$vci) = split(' ',$compare_lines); push @{$HoL_compare_priv{$router}}, $interface_name; } } my %no_priv_matches; foreach my $key (keys %HoL_compare_priv) { push @{$no_priv_matches{$key}}, $HoL_compare_priv{$key} unless exists $HoL_priv{$key}; } foreach my $group (keys %no_priv_matches) { print "New interconnects for $group are:\n"; foreach (@{$no_priv_matches{$group}}) { print "\t@{$no_priv_matches{$group}}\n"; } }
When run, prints:
New interconnects for vienna1-nbr2 are: ARRAY(0x1e9184) New interconnects for crtntx1-cr8 are: ARRAY(0x1df388) New interconnects for washdc3-br1 are: ARRAY(0x1e91e4) New interconnects for chcgil2-cr1 are: ARRAY(0x207358)
How can I dereference those array references?

Replies are listed 'Best First'.
(jeffa) Re: Dereferencing Hash of Array
by jeffa (Bishop) on Feb 20, 2001 at 20:53 UTC
    In your last chunk:
    foreach my $group (keys %no_priv_matches) { print "New interconnects for $group are:\n"; foreach (@{$no_priv_matches{$group}}) { print "\t@{$no_priv_matches{$group}}\n"; } }
    That inner foreach is not doing anything usefull, that's like saying this:
    foreach (@array) { print @array; }
    Do you really mean:
    foreach (@array) { print $_; }
    If that's the case, then maybe this will work:
    foreach my $group (keys %np_matches) { print "blah $group:\n"; foreach (@{$np_matches{$group}}) { print "\t@{$_}\n"; } }
    Hope this helps

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    
Re: Dereferencing Hash of Array
by TheoPetersen (Priest) on Feb 20, 2001 at 20:53 UTC
    Is this really what you want?
    foreach (@{$no_priv_matches{$group}}) { print "\t@{$no_priv_matches{$group}}\n"; }
    For each member of the array, you're printing the entire array? Seems like you'd want a dereferencing expression inside the loop there.
Re: Dereferencing Hash of Array
by mr.nick (Chaplain) on Feb 20, 2001 at 20:40 UTC
    You just need to use join or something similiar.

    foreach my $group (keys %no_priv_matches) { print "New interconnects for $group are:\n"; foreach (@{$no_priv_matches{$group}}) { print "\t".join(",",@{$no_priv_matches{$group}})."\n"; } }
      Thanks for the reply, but that returns the same result as the code that I posted.
        Sorry, my mistake, I didn't see the double arrays. Something like this will work:
        foreach (@{$no_priv_matches{$group}}) { for my $x (@$_) { print "$x "; } }