Reputation: 35
I'm close to get me crazy.
I have an array that seems to be ok. My array contains filenames (as keys) and full path on the values of the array. I checked that it's working.. up to here ok. Here is my code:
open (FILE, "comb_d.txt");
@l = <FILE>;
foreach $line (@l) {
chomp($line);
my @linea = split(/separator/,$line);
$hash_d{$linea[0]} = $linea[1];
}
As I said.. it works, because I verified that:
foreach my $llave (keys %hash_o) {
print "$llave = $hash_o{$llave}\n";
}
and it gives me full hash without issues..
Here comes the problem. I don't want to use all filenames (all keys) on my array, just a set of them. actually, there is a set of keys stored on @isect
. But when I run:
foreach my $llave ( @isect ) {
print "$llave = $hash_o{$llave}\n";
}
My result is:
filename1 =
filename2 =
I'm pretty sure that the elements on @isect
exist as keys of %hash_o
.
Help please
Thanks!!
Upvotes: 0
Views: 129
Reputation: 29854
For something like this, Data::Dumper
is your friend.
use Data::Dumper qw<Dumper>;
...
$hash_d{$linea[0]} = $linea[1];
say Dumper( \%hash_d );
}
And then later:
say Dumper( \@isect );
say Dumper( \%hash_o );
You're spending a lot of time doing what Data::Dumper
does for a light snack. And with each attempt at trying to do this, because it's Perl code and because you may not be up to speed with Perl, you're spending time debugging your debug code, instead of getting a solution done.
NOTE: Dumping is not an acceptable replacement for reading the API of an object, in Object-oriented Perl, as I explain here. But especially with unblessed hashes (see bless
or perlobj
), where it's just structured data that you want to know how to get at--it's the way to go.
Finally, here's where I mention that my favorite tool is Smart::Comments
. Where you do this:
use Smart::Comments;
...
### %hash_d
### @isect
### %hash_o
And watch the magic.
Upvotes: 1