[TriLUG] Perl CSV

William Sutton william at trilug.org
Sat Nov 16 23:05:11 EST 2013


Consider Text::CSV::Encoded if you have to deal with Unicode.

That said, anything outside of the standard quote/comma CSV files (in 
Litigation Support, they tend toward \x14 delimiters and \xfe quotes), you 
pretty much end up rolling your own splitter because of module parsing 
bugs.

William Sutton

On Sat, 16 Nov 2013, Greg Brown wrote:

> ah..... nice.  I run into quoted commas rarely but when I do it's a royal
> pain.  Cool, I'll toss that module in the toolbox to be called upon for
> such occasions.  Thanks!
>
>
> On Sat, Nov 16, 2013 at 6:59 PM, Aaron Joyner <aaron at joyner.ws> wrote:
>
>> CSV always gets interesting when you start handling quoted fields, which
>> might include embedded commas...
>> On Nov 16, 2013 6:29 PM, "Greg Brown" <gwbrown1 at gmail.com> wrote:
>>
>>> Interesting.  What benefits do you find using the Perl Text::CSV module.
>>  I
>>> work with .csv files literally all the time (no joke) but I've stuck with
>>> the tried and true method of the following:
>>>
>>> my $infile=somecsvfile.csv
>>> my $line;
>>> my @line;
>>>
>>> open(INFILE,$infile) || die "can't open $infile: $!\n";
>>>
>>> foreach $line (<INFILE>) {
>>>
>>>      chomp($line);
>>>      $line =~ s/\s+/ /g; # get rid of extra spaces
>>>      @line = split(/\,/,$line); # split the line at the commas
>>>
>>>      # send hostname and IP address to the subscript and ssh to device
>>>
>>>
>>>
>>>
>>>
>>>
>>> }
>>>
>>>
>>>
>>> On Thu, Nov 14, 2013 at 2:46 PM, Brian McCullough <bdmc at buadh-brath.com
>>>> wrote:
>>>
>>>> On Thu, Nov 14, 2013 at 02:21:37PM -0500, Brian McCullough wrote:
>>>>> I am sure that somebody here has some experience with the Perl
>>> Text::CSV
>>>>> mondule.
>>>>
>>>> Call off the dogs, thanks.
>>>>
>>>>
>>>>> I am trying to use it again, but every row, after $csv->parse, is
>>>>> reporting that there is only one element in the array.
>>>>>
>>>>>       $status = $csv->parse( $row ) ;
>>>>>       @cols = $csv->fields ;
>>>>>       $col_cnt = @cols ;
>>>>
>>>> I found that I was much more successful removing the above, and
>>>> replacing it with:
>>>>
>>>>  @cols = @$row ;
>>>>  $col_cnt = @cols ;
>>>>
>>>>
>>>> Go figure, as they say.
>>>>
>>>>
>>>> --
>>>> This message was sent to: Greg Brown <gwbrown1 at gmail.com>
>>>> To unsubscribe, send a blank message to trilug-leave at trilug.org from
>>> that
>>>> address.
>>>> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
>>>> Unsubscribe or edit options on the web  :
>>>> http://www.trilug.org/mailman/options/trilug/gwbrown1%40gmail.com
>>>> Welcome to TriLUG: http://trilug.org/welcome
>>>>
>>> --
>>> This message was sent to: Aaron S. Joyner <aaron at joyner.ws>
>>> To unsubscribe, send a blank message to trilug-leave at trilug.org from
>> that
>>> address.
>>> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
>>> Unsubscribe or edit options on the web  :
>>> http://www.trilug.org/mailman/options/trilug/aaron%40joyner.ws
>>> Welcome to TriLUG: http://trilug.org/welcome
>>>
>> --
>> This message was sent to: Greg Brown <gwbrown1 at gmail.com>
>> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
>> address.
>> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
>> Unsubscribe or edit options on the web  :
>> http://www.trilug.org/mailman/options/trilug/gwbrown1%40gmail.com
>> Welcome to TriLUG: http://trilug.org/welcome
>>
> -- 
> This message was sent to: William <william at trilug.org>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that address.
> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web	: http://www.trilug.org/mailman/options/trilug/william%40trilug.org
> Welcome to TriLUG: http://trilug.org/welcome
>


More information about the TriLUG mailing list