now, moving on to do more interesting stuff with hashes...I am having problems with new $k and $v to already existing read in hash .
can you help debug this piece?
where I attempt to check in data2 with already existing hash{key}=$value??
I added this piece to the code which previously loaded the hash from 1st file.
<data>
uno = uno
due = dos
tre = tres
quattro = quatro
cinque = cinco
<\data>
<data2>
uno => tree
due => dos
tre => tres
quattro => cinco
cinque => cinco
sei => seis
<\data2>
use strict;
use warnings;
use Data::Dump qw(dump);
use Storable; #don't know what this does yet.
my %hash;
open my $in, '<',"./test_data.txt" or die ("can't open the file:$!\n")
+;
while (<$in>){
chomp;
my ($key, $value)= split (/\s*=\s/);
$hash{$key}=$value;
}
close $in;
## <new code>
open my $in2,'<',"./test_data2.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:$1\n";
while (<$in2>){
chomp;
my ($key,$value) = split (/\s*=\s/); #splits row into 2 col
#will check if new key,value matches then print to another file for f
+un.
if exists $hash{$keys}{
dump \$out;
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.