OK. Well, first use: (a) use strict; (b) use warnings; (c) my variables.

Now, in your input loop you have:

@t = split(/\t/, $_) ; $t[4]= $AB{[4]} ;
which is a horrible mess :-( What you want to do is:
$AB{$alpha_numeric_field} = $numeric_field ;
where the two fields are elements of @t, I cannot tell which.

The output process contains:

if ($var1[2] and exists $Ab{$var1[2]}) { print OUT "$var1[0]\t$var1[1]\t$var1[2]\t$AB[4]\n" ; }
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 !).

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:

@var1 = split(/\t/,$_) ;
you can write (for example):
($field_name, $other_field, $further_field, ...) = split(...) ;
then you have each field in a variable with a meaningfull name -- more friendly than $var1[2] etc.


In reply to Re^3: Compare Arrays, Return Values by gone2015
in thread Compare Arrays, Return Values by de2425

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.