Thank you everyone for your suggestions. I need to clarify a little more.

wfsp and GrandFather: I apologize for misplacing the 'if' statement. I accidentally pasted it outside the inner loop, but in my code it is inside the inner loop. The condition works in every instance, except on the last item in either array.

GrandFather: I thought about using a hash, but I need to gather the files in order (by column) so that I can correctly order the second one. I cannot think of how to do that with a hash. It seems that a 2D array would be optimal. Do you a suggestion on how to do it with a hash?

AnomolousMonk: What I mean by the comment about "eventually" reading the whole file, I mean that I will eventually read it into a 2D array during that loop, but I simplified it for the posting. However, it still has the same behavior as is. I kept the loop to maintain what I would do later. Is there a better way to read in each row and column?

jethro: Thank you for suggesting Dumper, I was not aware of it. It also perfectly shows my problem. When it prints the last item in both arrays, it's all messed up:

#### BEGIN ####
$VAR215 = 'MS02-19196-A6-DCIS';
$VAR216 = 'MS02-19196-A6-INVASIVE';
$VAR217 = 'MS01-9167-A7-DCIS';
';AR218 = 'MS06-1878-D2-DCIS
#### END ####

That is exactly how it prints. Also, when it gets to the if condition, the condition fails. However, at that very moment, I can print the value in the debugger with "p $sample1"

Anomolous Monk suggested that it could be a problem with extra tab(s) at the end of the line, but I have double checked that. This is really confusing to me. I also tried another file that is totally unrelated to what I'm doing, and it had the same behavior.

I would like to post the file, but it has 218 columns and I don't see a way to upload it.

Thanks for your help.


In reply to Re: Misunderstood array behavior by Anonymous Monk
in thread Misunderstood array behavior by Anonymous Monk

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.