> On Feb 4, 2004, at 6:50 AM, Mark Martin wrote: > > > I'm pulling my hair out trying to find out how to upload this data. My > > files can vary in numbers of rows and columns but the x and y axis > > always contain the same type of metadata - in my case cost centre and > > cost item. A sample of the data would look like : > > > > cost_centre,stationery,postage,furniture,training,advertising > > 1001,£10.56,£8,£500.99,£1500,£300.99 > > 1002,£40.50,£12.35,£0,£0,£450 > > Generally, when I have data like this, my favorite thing to do is to > build a hash out of each row, then use whatever I want by name. Like > this: > > my $header = <>; > my @cols = split /,/, $header; # store column names for later use > > while (<>) { > my @fields = split /,/; > > # next we load our hash > my %record = map { ($cols[$_], $fields[$_]) } 0..$#fields; > > # and here we can use it > print "$record{cost_centre} $record{stationery}\n"; # or whatever > } > > From there you're problem is simply building an SQL statement and > feeding it to the DBI. Is that enough to get you going? > > James >
If your CSV is at all complex (read: can have other delimiters or quoted strings, etc.) I would suggest investing in, especially since its free, Text::CSV_XS: http://search.cpan.org/~jwied/Text-CSV_XS-0.23/CSV_XS.pm http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>