in reply to build hash from csv file

Hope you don't mind a few comments on your code.

Firstly, just spliting on commas and removing double quotes is only going to work on the most basic CSV files. Much better to look at using Text::ParseWords (which comes with Perl) or Text::CSV_XS (which doesn't). Both of these will handle more complex CSV files than your code does.

Secondly, it seems a bit wasteful to loop round your @linedata array copying each element separately into a second-level hash. If fact I'd question the use of a hash there at all. If you're using a hash whose keys are low numbered integers, then you're much better off using an array. And as you've already got an array, you can just store a reference to that in your data structure.

$hash{$lineno} = \@linedata;

Hope this is useful.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: build hash from csv file
by tcf03 (Deacon) on Sep 19, 2005 at 13:24 UTC
    Don't mind at all. I was looking at the Text::CSV::Simple - Ill look at the others now though - I was just a bit perplexed as to how to merge all the data back together from different files with unknown fields. Thanks for your input.

    Ted
    --
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson