in reply to Re: How to compare two associative arrays efficiently
in thread How to compare two associative arrays efficiently

thanks, but again have a doubt. I got that my arrays(hashes) have only keys and values are undef. but my flat file is like 1111 2222 3333 4444 which I have loaded into an an hash say %hash1 and I was assuming that with this 1111 and 3333 will become the key for values 2222 and 4444 respectively, but I think I was wrong. So I have two flat files just like the above sample and which I have loaded into two separate hashes say %hash1,%hash2, and if they have any not common values/key then store into another array or hash, does not matter. Please help me out...
  • Comment on Re^2: How to compare two associative arrays efficiently

Replies are listed 'Best First'.
Re^3: How to compare two associative arrays efficiently
by ikegami (Patriarch) on Oct 12, 2006 at 21:57 UTC

    It can be loaded either way. It's totally up to you how you store the info in the hash.

    Anyway, here's code that should accomplish your goal.

    use strict; use warnings; my $fn_assn = ...; my $fn_pssn = ...; my @assns; { open(my $fh_assn, '<', $fn_assn) or die("Unable to open assn file \"$fn_assn\": $!\n"); chomp(@assns = <$fh_assn>); } my @pssns; { open(my $fh_pssn, '<', $fn_pssn) or die("Unable to open pssn file \"$fn_pssn\": $!\n"); chomp(@pssns = <$fh_pssn>); } { my %pssns = map { $_ => 1 } @pssns; my @unique_assns = grep { not exists $pssns{$_} } @assns; print("The following ASSNs have no corresponding PSSNs:\n"); print("$_\n") foreach @unique_assns; } print("\n"); { my %assns = map { $_ => 1 } @assns; my @unique_pssns = grep { not exists $assns{$_} } @pssns; print("The following PSSNs have no corresponding ASSNs:\n"); print("$_\n") foreach @unique_pssns; }
Re^3: How to compare two associative arrays efficiently
by blazar (Canon) on Oct 12, 2006 at 22:02 UTC
    thanks, but again have a doubt. I got that my arrays(hashes) have only keys and values are undef. but my flat file is like 1111 2222 3333 4444 which I have loaded into an an hash say %hash1 and I was assuming that with this 1111 and 3333 will become the key for values 2222 and 4444 respectively, but I think I was wrong.

    Indeed if you do something like

    my %hash=qw/1111 2222 3333 4444/;

    then %hash will have the structure you describe. However generally keys and associated values have a "different nature". Nothing prohibits them to be homogeneus, but I see no reason for them to be so in this case, so is it really what you want?

    So I have two flat files just like the above sample and which I have loaded into two separate hashes say %hash1,%hash2, and if they have any not common values/key then store into another array or hash, does not matter. Please help me out...

    I wish I could help you but it's hard to make sense of "common values/keys". Also despite your efforts the expression "then store into another array or hash" is still missing the object to be stored into whatever.