sub _get_row {
my @row;
my $q_sep = quotemeta($self->{sep});
my $match_sep = qr/\G$q_sep/;
my $start_field = qr/\G(")|([^"$q_sep]*)/;
# This loop is the heart of the engine
while ($line =~ /$start_field/g) {
if ($1) {
push @row, _get_quoted();
}
else {
# *** ALWAYS FALLS HERE ***
push @row, $2;
}
my $pos = pos($line);
# *** THIS ENTIRE IF BLOCK IS NEVER EXECUTED ***
if ($line !~ /$match_sep/g) {
if ($pos == length($line)) {
return @row;
}
else {
my $expected = "Expected '$self->{sep}'";
confess("$expected at $self->{filename}, line $., char $pos");
}
}
}
confess("I have no idea how parsing $self->{filename} left me here!");
}
####
Date,SessionID,Category,Number,Description,File,Line,Column,Source,ASPCode,ASPDescription
"3/25/2002 10:25:18 AM","971874429","Orders.GetHTML(#12).GetAllUserOrders(#28)msxml3.dll","0x80004005","Unknown method.
tracking[-->last()<--]","/Default.asp","14","-1",,,
"3/25/2002 10:25:47 AM","971874360","Orders.GetHTML(#12).GetAllUserOrders(#28)msxml3.dll","0x80004005","Unknown method.
tracking[-->last()<--]","/Default.asp","14","-1",,,
"3/25/2002 10:29:49 AM","971874312","Active Server Pages","0x8002802B","Create object failed","?","0","-1",,,"An error occurred while creating object 'oCheckOut'."
"3/25/2002 10:45:24 AM","971874360","Orders.GetHTML(#20)msxml3.dll","0x80004005","The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.","/Default.asp","14","-1",,,
"3/25/2002 10:46:04 AM","971874509","Microsoft OLE DB Provider for SQL Server","0x80040E14","Line 1: Incorrect syntax near ','.","/Default.asp","169","-1",,,
"3/25/2002 12:01:00 PM","980227415","Receipt.GetHTML(#19).GetOrder(#26)Account","0x800A0005","Invalid procedure call or argument","/Default.asp","15","-1",,,
####
#!/usr/bin/perl -w
use strict;
use Text::xSV;
print "Creating object...\n";
my $csv = Text::xSV->new;
print "Opening file...\n";
$csv->open_file( 'sample.csv' );
print "Binding header...\n";
$csv->bind_header();
print "Entering loop...\n";
while ( $csv->get_row() ) {
print " found row\n";
}
print "Finished loop.\n";