building on my perl skills with incremental test cases I am making up as I go...but hashes are still a bit confusing so I need a little guidance on decoding how these work.

I made up some little program to use hashes.

check if the number is found in both files. I used exist for keys but the output is not coming out to be what I want, can you advice me on how to do this properly? I thought by checking the keys I'd get s single key=value but French numbering isn't there ...

1st data

uno = uno due = dos tre = tres quattro = quatro cinque = cinco sei = seis sette = siete otto = ocho nouve = nueve dieci =diez

2nd data *corrected typo on 2,3 in French.

uno = un due = deux tre = trois quattro = quatre cinque = cinq sei = six sette = sept dieci = dix

OUTPUT:Italian => Spanish , French

uno => uno, un due => dos , deux tre => tres , trois quattro => quatro, quatre cinque => cinco , cinq sei => seis, six sette => siete, sept dieci => diez, dix
use strict; use warnings; use Data::Dump qw(dump); use Storable; #don't know this yet but let's try soon. my %hash; #opening my file handles; adding recommendations with naming extention +s open my $in, '<',"./test_data.txt" or die ("can't open the file:$!\n") +; open my $in1,'<',"./test_data1.txt" or die ("can't open file : $!\n"); open my $out ,'>' ,"./test_data_out.txt" or die "can't open the file f +or write:$!\n"; open my $out1 ,'>',"./test_data_out1_no_match.txt" or die "can't open +file for write:$!\n"; while (<$in>){ chomp; my ($key, $value)= split (/\s*=\s*/); #greedy matching for better +regex coverage as per Ken $hash{$key}=$value; } close $in; while (<$in1>){ chomp; my ($key,$value) = split (/\s*=\s*/); #splits row into 2 col. #checks for keys that EXIST in both then prints...? if (exists $hash{$key}){ print $out "$key => $hash{$key} , $value \n"; } else { print $out1 "$key => $value \n"; } } close $in1; close $out; close $out1;

In reply to Need advice on checking two hashes values and keys by perlynewby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.