[GRLUG] Some perl help

scott.tanner at comcast.net scott.tanner at comcast.net
Sat Jul 2 22:41:49 EDT 2011


(Apologies is this came through twice. ) 

David, 
I know this doesn't exactly answer your question, but I've used the Text::CSV_XS module for a while to parse CSV files and have had with good results. As Adam alluded to, CSV can get squirrely pretty fast. 

http://search.cpan.org/~hmbrand/Text-CSV_XS-0.82/CSV_XS.pm 


Regards, 
Scott 



David Pembrook < david at pembrook.net > wrote: 
>I'm fluent enough in perl to be dangerous. I have a line from a csv 
>file and I want the "columns" in an array without any quotes. Some 
>columns have them, some don't so I can't count on their presence. 
>The quick and dirty way I came up with used a temp array and a counter 
>and know that has to be a better way to handle this. 
> while (<FILE>) { 
> @temp_values2 = split(",", $_); 

String splitting is an evil and wrong way to read a delimited record; 
doing so will fail in a fantastic variety of ways. I'm not a Perl 
developer but I'm certain Perl must provide a standard module for 
reading delimited data sets. In Python this would be the "csv" module - 
which allows you to specify field delimiter, line terminator, and field 
quoting style. Don't forget that text files also have encoding - one 
cannot assume text data is ASCII (especially if a user can get anywhere 
near it using cut-n-paste). If it isn't straight-ASCII your string 
splitting will fail in mysterious cases that on visual inspection look 
fine. 

-- 
Adam Tauno Williams 
-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shinobu.grlug.org/pipermail/grlug/attachments/20110703/9afff557/attachment-0001.html>


More information about the grlug mailing list