McDarren has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my $datafile = "stuff.csv"; my @fields; my $data; my $flag; open DATA, "<$datafile" or die "Could not open $datafile:$!\n"; while (<DATA>) { chomp(); # If the flag hasn't been set, this must be the header (first) lin +e if (!$flag) { # Throw away the first two fields (#, username) in the header (undef, undef, @fields) = (split /\t/); $flag++; } else { my ($user, @userdata) = (split /\t/); my $i = 0; while ($i <= $#fields) { $data->{$user}{$fields[$i]} = $userdata[$i]; $i++; } } } close DATA;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing CSV into a hash
by GrandFather (Saint) on Sep 19, 2005 at 21:53 UTC | |
by McDarren (Abbot) on Sep 19, 2005 at 22:05 UTC | |
by GrandFather (Saint) on Sep 19, 2005 at 22:30 UTC | |
|
Re: Parsing CSV into a hash
by jZed (Prior) on Sep 19, 2005 at 23:53 UTC | |
|
Re: Parsing CSV into a hash
by davidrw (Prior) on Sep 19, 2005 at 22:58 UTC | |
|
Re: Parsing CSV into a hash
by dragonchild (Archbishop) on Sep 20, 2005 at 02:09 UTC | |
by tilly (Archbishop) on Sep 20, 2005 at 08:00 UTC | |
|
Re: Parsing CSV into a hash
by Skeeve (Parson) on Sep 20, 2005 at 05:08 UTC | |
|
Re: Parsing CSV into a hash
by McDarren (Abbot) on Sep 21, 2005 at 04:30 UTC |