On Jan 13, 2007, at 6:29 PM, xavier mas wrote:
hello list,
I am trying to find if an element in one primary file (transformed
to array)
is included in two other different secondary files (transformed to
arrays,
too); the result is going to be printed as 1 or 0:
According to the code that's 1 or -1.
...
#creating arrays from its text files
@img_array=<IMATGES>; @dict_array=<DICT>; @in_array=<IN>;
#creating hashes from its arrays
foreach $in (@in_array) {chomp($in); $in_hash{$in}= 1;}
foreach $in (@dict_array) {chomp($in);$dict_hash{$in}= 1;}
foreach $in (@img_array) {chomp($in);$img_hash{$in}= 1;}
#searching primary element in secondary hashes
while (($key, $value) = each %in_hash) {
if (exists $dict_hash{$key}) {$dic_flag="1";}else {$dic_flag="-1"}
if (exists $img_hash{$key}) {$img_flag="1";}else {$img_flag="-1";}
#printing result
print "$img_flag, $dic_flag\n";
A bit of air would improve readability, the code is easy but dense
just because of lack of layout.
but it seems 'exists' function doesn't fly to do this -the element
isn't
always found into the secondary hashes. Any suggestion of why it
doesn't and
how to do it?
Besides de potential mismatch given by the fact that the "img" hash
has an "img" flag, but the "dict" hash has a "dic" flag (everything
seems correct in that snippet anyway), I see no problem. Could you
please send a minimal, self-contained code with minimal example files
that let us reproduce the issue?
-- fxn
PS: Please turn strict and warnings on.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/