in reply to Re^2: Compare Arrays, Return Values
in thread Compare Arrays, Return Values
OK. Well, first use: (a) use strict; (b) use warnings; (c) my variables.
Now, in your input loop you have:
which is a horrible mess :-( What you want to do is:@t = split(/\t/, $_) ; $t[4]= $AB{[4]} ;
where the two fields are elements of @t, I cannot tell which.$AB{$alpha_numeric_field} = $numeric_field ;
The output process contains:
which looks as though it would be OK, but for $AB[4], which ought to be $AB{$var1[2]}. (Oh. And it should be $AB{...} in the if !).if ($var1[2] and exists $Ab{$var1[2]}) { print OUT "$var1[0]\t$var1[1]\t$var1[2]\t$AB[4]\n" ; }
use strict would have picked up the $Ab{} mistake (undefined hash %Ab) and the use of $AB[4] (undefined array @AB). It would not, however, have picked up $AB{[4]}, which is the kind of honest-to-goodness inscrutability that Perl is justly famous for, and which one grows to be deeply fond of.
BTW, rather than:
you can write (for example):@var1 = split(/\t/,$_) ;
then you have each field in a variable with a meaningfull name -- more friendly than $var1[2] etc.($field_name, $other_field, $further_field, ...) = split(...) ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Compare Arrays, Return Values
by de2425 (Sexton) on Aug 28, 2008 at 17:25 UTC |