http://www.perlmonks.org?node_id=493314


in reply to Re: Parsing CSV into a hash
in thread Parsing CSV into a hash

Okay, that's one part of my problem solved, thanks :)

Let me just work through that to make sure I have it....
It works from right to left, yes?
We iterate through each item in @fields, grabbing the associated item from @userdata, then assigning it to the hash, yes?

Replies are listed 'Best First'.
Re^3: Parsing CSV into a hash
by GrandFather (Saint) on Sep 19, 2005 at 22:30 UTC

    That's right. Note also that if there are too few fields in a line this simply assigns undef rather than generating an invalid access as your original code did.

    If you are sure that the first line contains the header line then you can simply:

    $_ = <DATA> or die "Empty file"; chomp; # Throw away the first two fields (#, username) in the header (undef, undef, @fields) = (split /\t/);

    before the loop.


    Perl is Huffman encoded by design.