This is potentially a tough one to solve without the data, and the subroutine. Are their duplicate lines in your data? What's $index doing in your script? I don't see it being used anywhere in the code you've posted.

A main worry here is that you may not have the right kind of data structure: you've got three arrays, but I'm not sure about how the data in them are related. You loop over one array, and pass elements from different arrays to the subroutine. Could you perhaps say more about your data structure (e.g. what data is contained within a single record) ? I would guess, from your description, that an array of array references (which is how one implements a two-dimensional array in Perl) would help to solve your problem.

an aside concerning that $index variable : foreach is actually a synonym of for as far as Perl is concerned, but you seem to be mixing up the two ways of using them to iterate over an array (by iterating over the indices of the array, or by iterating -- sans index -- over the array)

Philosophy can be made out of anything. Or less -- Jerry A. Fodor


In reply to Re: Foreach Complications by arturo
in thread Foreach Complications by ImpalaSS

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.