in reply to Re^3: load a file in memory and extract parts
in thread load a file in memory and extract parts

Actually that didn't work, I get the same error at line foreach my $row (0..@file_array-1) Can you try it with tie by loading the following file col1|col2|col3|col4|col5 data1|data2|data3|data4|data5 data1b|data2b|data3b|data4b|data5b Thanks

  • Comment on Re^4: load a file in memory and extract parts

Replies are listed 'Best First'.
Re^5: load a file in memory and extract parts
by afoken (Chancellor) on May 06, 2015 at 19:31 UTC

    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". ;-)