As long as you're sure that there aren't any commas in your data, you
could always do this:

    my @records = split(/,/,$line,17);

This will limit your total records to 17, and will dump the rest into
the 17th record.  Then you can split the last record again if you want.

If you have some commas in your data then you might have to adjust your
logic to include records that look like this:

1,1,G-9999999,G-9999999,"SFC-999999",2006/06/01,11:00,999,9,9,$9999.99,9
99
999999,"999,999,999,999",999999,9,9,23,24,25,26,27


-----Original Message-----
From: RICHARD FERNANDEZ [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 08, 2006 8:18 AM
To: beginners@perl.org
Subject: parsing a CSV file with more fields than column names

Hello All,

I'm just trying to get some ideas for the best way to approach this...

I have a CSV file whose first line is a header. According to this header
there should be 17 values per line. Unfortunately this is not the case.
It seems that the first 16 header values match up with the first 16
values in each line, but for the 17th header item, there may be 1 or
more comma separated values associated with it! Here is a sample line
with header:

Num,Env Num,Envelope,Transaction,Lockbox,Date,Time,Batch,Batch
Item,Check,Check Amount,ABA/RT,Account Num,Check Num,Check
Image,Envelope Image,Page Images

1,1,G-9999999,G-9999999,SFC-999999,2006/06/01,11:00,999,9,9,$9999.99,999
999999,999999999999,999999,9,9,23,24,25,26,27 


As you can see the 17th value is "23", but really there are 5 values
associated with "Page Images", 23-27.

I've been playing with Tie::Handle::CSV, but I don't see a way to have
it pick up more that one value per hash key. What I need is a way to
specify "all remaining values" a la split, perhaps with an array ref.

Maybe Tie::Handle::CSV isn't the best choice? 

Any thoughts are appreciated.

TIA

richf

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




--
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