in reply to Need advice on checking two hashes values and keys

Uh... you iterate over the file while (<$in1>){ but inside that loop you iterate AGAIN? over foreach my $key (sort keys %hash){
That does not make much sense. A hash is made such that you do not need to iterate over them. You are treating the hash like it was an array.

while (<$in1>){ chomp; my ($key,$value) = split (/\s*=\s/); if (exists $hash{$key}){ print $out "$key => $hash{$key}, $value \n"; }else{ print $out1 "$key => $value \n"; } }

Replies are listed 'Best First'.
Re^2: Need advice on checking two hashes values and keys
by perlynewby (Scribe) on Jun 03, 2015 at 22:43 UTC

    GRR, Yes, the iteration was an previous attempt to use all "IF THEN " checks on the Keys and values before abandoning it and deciding to ask for help so I can learn hashes by coding practice. I should have commented it out foreach loop.

    your code did clear a bit on hashes for me though. I was wrongly thinking how "exists" worked. I wrongly infered that if key "exists" in both files,it would automatically keep the 1 key and ,regardless if there were many identical keys with other values, and append the new values to it. going to reread that section again. thanks.

    will soon play with "define" as per the other code example...so much to learn on hashes.

    I get this error but code didn't crashed...why? what does this mean? Use of uninitialized value $value in concatenation (.) or string at C:\Users\Alberto\Documents\NetBeansProjects\PerlProject\Perl Essentials\giocando_con_il'ordinamento_hashes.pl line 39, <$in1> line 9.

      never mind on error on concatenation...it was my test_data format issue...extra spaces trailing on one file.