Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

(dkubb) Re: (2) Comparing contents of 2 Hash of Arrays

by dkubb (Deacon)
on Feb 20, 2001 at 09:33 UTC ( [id://59579]=note: print w/replies, xml ) Need Help??


in reply to Comaring contents of 2 Hash of Arrays

Tuna, I think this does what you want.

If an element exists in %HoL_compare_pub, but not inside %HoL_pub, then push it into the array-ref $no_matches{$key}:

my %no_matches; foreach my $key (keys %HoL_compare_pub) { push @{$no_matches{$key}}, $HoL_compare_pub{$key} unless exists $HoL_pub{$key}; }

Replies are listed 'Best First'.
Re: (dkubb) Re: (2) Comparing contents of 2 Hash of Arrays
by sierrathedog04 (Hermit) on Feb 20, 2001 at 17:56 UTC
    I tested your program at my site and it works:
    use strict; use CGI qw(:standard); print header; print start_html("Hash Test"); my %HoL_compare_pub=('NL','The Netherlands','BE','Belgium','DE','Germa +ny','MC','Monaco','ES','Spain'); my %HoL_pub=('NL','The Netherlands','BE','Belgium'); my %no_matches; foreach my $key (keys %HoL_compare_pub) { push @{$no_matches{$key}}, $HoL_compare_pub{$key} unless exists $HoL_pub{$key}; } foreach my $noMatchKey (keys %no_matches){ print "$noMatchKey\n"; } print end_html;

    What I don't understand is why you describe $no_matches{$key} as being an array-ref. It seems to me that it is simply an element of a hash.

    $no_matches{$key) does not seem to refer to anything outside of %no_matches. So why is it an array-ref?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://59579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-20 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found