If you want to learn by experimenting, remember that a string and an array are very different data structures. Tie::File gives you an array of strings, but you treat it like an array of arrays (containing strings). Perl constructs arrays of arrays as arrays containing array references. See perldsc. Use Data::Dumper to see what your data actually looks like.

If you just want to solve the original problem, don't parse CSV manually, use Text::CSV_XS to get your data in a format that you can work with. Consider using DBI and DBD::CSV instead for an even shorter way (the SQL INNER JOIN proposed by locked_user sundialsvc4) to read AND combine AND export your data. Note that the DBI way also allows to migrate the program to SQLite or any other database in a later version.

Unless you know your CSV files in every single detail, and especially unless you are absolutely sure that they don't contain nasty things like optional quotes, quoted separator chars, escaped quotes, newlines in data, NULLs, binary data, and so on, you better AVOID split and use Text::CSV_XS. split alone can't handle any of those problems, Text::CSV_XS can handle all of them.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^5: load a file in memory and extract parts by afoken
in thread load a file in memory and extract parts by healingtao

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.