in reply to Re: Need advice on checking two hashes values and keys
in thread Need advice on checking two hashes values and keys
I appreciate all the advice and examples to manipulate hash, hash table, code improvement and will do all of these with your help.
should I create a new thread for each example or stick with this thread? maybe some other newbie can learn from it.
Ok, I've been playing with hash ref to get a 2 element hash.
hasn't worked yet. will you provide some instruction/teach/explain the error I did on hash ref? error it gave me.
Can't use string ("dos") as an ARRAY ref while "strict refs" in use at C:\Users\Alberto\Documents\NetBeansProjects\PerlProject\Perl Essentials\hash_ref_6_4.pl line 34, <$in1> line 1.
use strict; use warnings; use Data::Dump qw(dump); my %hash; #my file handles UNTIL I figure how to install the Inline::File module + to netbeans IDE 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"; #creating hash while (<$in>){ chomp; my ($key,$value)= split(/\s*=\s*/); #conto di spazio prima o dopo +la parola $hash{$key}=$value; } close $in; #using the first hash while (<$in1>){ chomp; my($key,$value)=split/\s*=\s*/ ; #push the value to existing hash as to get reference if key exists # %hash =( It => [Spa Fre]) #using one hash as per Ken code suggestion?? push @{$hash{$key}},$value if $hash{$key}; #non so come funzio +na "push" print $out dump (\%hash); } close $in1; close $out; close $out1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Need advice on checking two hashes values and keys
by aaron_baugher (Curate) on Jun 04, 2015 at 21:54 UTC | |
by perlynewby (Scribe) on Jun 04, 2015 at 23:23 UTC | |
by aaron_baugher (Curate) on Jun 05, 2015 at 02:01 UTC | |
by Anonymous Monk on Jun 09, 2015 at 18:41 UTC | |
by aaron_baugher (Curate) on Jun 09, 2015 at 20:52 UTC | |
|