A
Alex Hunsley
I'm using CSV_XS to parse a CSV file.
One of my CSV fields beings with the 0 char as it is a phone number, e.g.:
"0123456789"
However, the string returned from CSV_XS when I parse the line doesn't
have the leading 0. I think this may be because it is intrepretting it
as a number at some point, and hence dropping the leading 0?
Anyway, my code for reading my file is as follows:
use DBI;
use DBD::mysql;
use Text::CSV_XS;
use File::Find;
#$vah = "07";
#print $vah;
#exit;
$csv = Text::CSV_XS->new(
{
'quote_char' => '"',
'escape_char' => '"',
'sep_char' => ',',
'binary' => 0,
'always_quote' => 1
}
);
open(INPUT,"<sheet.csv") || die "couldn't open input";
while (<INPUT>) {
$inputLine = $_;
#skip blank lines
if ( $inputLine =~ /^\s*$/ ) {
next;
}
# parse a CSV string into fields
$readStatus = $csv->parse($inputLine);
@columns = $csv->fields(); # get the parsed fields
# this folllowing line output lines like 1234
# rather than the expected 01234!
print "$columns[9]\n";
}
close(INPUT);
grateful for any guidance here...
thanks
alex
One of my CSV fields beings with the 0 char as it is a phone number, e.g.:
"0123456789"
However, the string returned from CSV_XS when I parse the line doesn't
have the leading 0. I think this may be because it is intrepretting it
as a number at some point, and hence dropping the leading 0?
Anyway, my code for reading my file is as follows:
use DBI;
use DBD::mysql;
use Text::CSV_XS;
use File::Find;
#$vah = "07";
#print $vah;
#exit;
$csv = Text::CSV_XS->new(
{
'quote_char' => '"',
'escape_char' => '"',
'sep_char' => ',',
'binary' => 0,
'always_quote' => 1
}
);
open(INPUT,"<sheet.csv") || die "couldn't open input";
while (<INPUT>) {
$inputLine = $_;
#skip blank lines
if ( $inputLine =~ /^\s*$/ ) {
next;
}
# parse a CSV string into fields
$readStatus = $csv->parse($inputLine);
@columns = $csv->fields(); # get the parsed fields
# this folllowing line output lines like 1234
# rather than the expected 01234!
print "$columns[9]\n";
}
close(INPUT);
grateful for any guidance here...
thanks
alex