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


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to