Created
November 1, 2011 00:03
-
-
Save kentfredric/1329456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
sub splitCommaNotQuote { | |
my ( $line ) = @_; | |
my @fields = (); | |
while ( $line =~ m/((\")([^\"]*)\"|[^,]*)(,|$)/g ) { | |
if ( $2 ) { | |
push( @fields, $3 ); | |
} else { | |
push( @fields, $1 ); | |
} | |
last if ( ! $4 ); | |
} | |
return( @fields ); | |
} | |
use Data::Dump qw( pp ); | |
my ( @lines ) = <DATA>; | |
my $content = join q{}, @lines; | |
chomp for @lines; | |
pp { content => [ splitCommaNotQuote( $content ) ] }; | |
pp { lines => [ map { [ splitCommaNotQuote( $_ )] } @lines ] }; | |
__DATA__ | |
COLLOQ_TYPE,COLLOQ_NAME,COLLOQ_CODE,XDATA | |
S,"BELT,FAN",003541547, | |
S,"BELT V,FAN",000324244, | |
S,SHROUD SPRING SCREW,000868265, | |
S,"D" REL VALVE ASSY,000771881, | |
S,"YBELT,"V"",000323030, | |
S,"YBELT,'V'",000322933, | |
S,"YBELT HAS A LINE | |
FEED IN IT",00000001, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
content => [ | |
"COLLOQ_TYPE", | |
"COLLOQ_NAME", | |
"COLLOQ_CODE", | |
"XDATA\nS", | |
"BELT,FAN", | |
"003541547", | |
"\nS", | |
"BELT V,FAN", | |
"000324244", | |
"\nS", | |
"SHROUD SPRING SCREW", | |
"000868265", | |
"\nS", | |
"\"D\" REL VALVE ASSY", | |
"000771881", | |
"\nS", | |
"\"YBELT", | |
"\"V\"\"", | |
"000323030", | |
"\nS", | |
"YBELT,'V'", | |
"000322933", | |
"\nS", | |
"YBELT HAS A LINE\nFEED IN IT", | |
"00000001", | |
"\n", | |
], | |
} | |
{ | |
lines => [ | |
["COLLOQ_TYPE", "COLLOQ_NAME", "COLLOQ_CODE", "XDATA"], | |
["S", "BELT,FAN", "003541547", ""], | |
["S", "BELT V,FAN", "000324244", ""], | |
["S", "SHROUD SPRING SCREW", "000868265", ""], | |
["S", "\"D\" REL VALVE ASSY", "000771881", ""], | |
["S", "\"YBELT", "\"V\"\"", "000323030", ""], | |
["S", "YBELT,'V'", "000322933", ""], | |
["S", "\"YBELT HAS A LINE"], | |
["FEED IN IT\"", "00000001", ""], | |
], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment