in reply to parsing malformed CSV with per column quote chars

It isn't CSV. So just write a parser for it. This isn't rocket surgery.

#!/usr/bin/perl -w use strict; my @data; while( <DATA> ) { my @row; while( /\G(?=.)/gc ) { my $val = undef; /\G\s*/gc; if( /\G'/gc ) { my $p = pos(); /\G(?:[^']+|'')*/gc; $val = substr( $_, $p, pos()-$p ); die "Unclosed '\n" if ! /\G'/gc; } elsif( /\G"/gc ) { my $p = pos(); /\G(?:[^"]+|"")*/gc; $val = substr( $_, $p, pos()-$p ); die "Unclosed \"\n" if ! /\G"/gc; } else { my $p = pos(); $val = substr( $_, $p, pos()-$p ) if /\G[^'",]+/gc; $val =~ s/\s*$//; } /\G\s*/gc; die "Bad data\n" if ! /\G(,|$)/gc; push @row, $val; } push @data, \@row; } __END__ 'PRODUCT CODE','CATEGORY','CATEGORY DESCRIPTION','CODE DESCRIPTION','O +PTIONAL CATEGORY','OPTIONAL CATEGORY DESCRIPTION' ' ','0 ','No Item',"INVALID CODE IN USER SUPPLIED DATA",' ',' ' '00100','1 ','Cat',"ORANGE CAT",' ',' ' '82131','94 ','Dog',"GREEN DOG",' ',' ' '82132','94 ','Dog',"'JOHNS' FLYING' DOG (Start 2001)",' ',' ' '82133','94 ','Dog',"MAGENTA DOG (End 2009)",' ',' '

Yep, not hard; worked the first try. Took a few minutes to write.

(Update: I neglected to post-process escaped quotation marks. Of course, no provision for escaped quotation marks was given in the original problem so I just implemented the simplest version, which might not be appropriate.)

- tye