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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |