I am a beginner at Perl, but am working on a team to import a csv file into an Access Database as a table. My part is really to write the SQL code which I am familiar with, but our team can't get the data from the csv file so I can manipulate it with SQL. We researched how to bring the csv file into an array and assign each point of the array a variable name so it can be written to the Access database using SQL. We have been using a sample code that is not working. Can anyone tell us either why it won't work or give us an example of what we can do. I have included the code followed by the errors we are getting.
Here is the code we are testing:
---------------------------------------------------
require Text::CSV;
my $csv = Text::csv->new;
my $column = '';
my $sample_input_string = '"I said, ""Hi!""",Yes,"",2.34,,"1.09"';
if ($csv->parse($sample_input_string)) {
my @field = $csv->fields;
my $count = 0;
for $column (@field) {
print ++$count, " => ", $column, "\n";
}
print "\n";
} else {
my $err = $csv->error_input;
print "parse() failed on argument: ", $err, "\n";
}
my @sample_input_fields = ('You said, "Hello!"',
5.67,
'Surely',
'',
'3.14159');
if ($csv->combine(@sample_input_fields)) {
my $string = $csv->string;
print $string, "\n";
} else {
my $err = $csv->error_input;
print "combine() failed on argument: ", $err, "\n";
}
--------------------------------------------
We are getting the following errors
Can't locate auto/text/csv/autosplit.ix in @inc (@inc contains: c:/perl/lib c:/perl/file/lib .)
at c:/perl/lib/autoloader.pm line 127
at c:/perl/lib/text/csv.pm line 23
can't locate object method "new" via package
"text::csv" at test1.pl line 4
------------------------
My script is called test1.pl and I am running it via a bat file.
Thanks for reading this in an attempt to assist!!!!
tmh
Here is the code we are testing:
---------------------------------------------------
require Text::CSV;
my $csv = Text::csv->new;
my $column = '';
my $sample_input_string = '"I said, ""Hi!""",Yes,"",2.34,,"1.09"';
if ($csv->parse($sample_input_string)) {
my @field = $csv->fields;
my $count = 0;
for $column (@field) {
print ++$count, " => ", $column, "\n";
}
print "\n";
} else {
my $err = $csv->error_input;
print "parse() failed on argument: ", $err, "\n";
}
my @sample_input_fields = ('You said, "Hello!"',
5.67,
'Surely',
'',
'3.14159');
if ($csv->combine(@sample_input_fields)) {
my $string = $csv->string;
print $string, "\n";
} else {
my $err = $csv->error_input;
print "combine() failed on argument: ", $err, "\n";
}
--------------------------------------------
We are getting the following errors
Can't locate auto/text/csv/autosplit.ix in @inc (@inc contains: c:/perl/lib c:/perl/file/lib .)
at c:/perl/lib/autoloader.pm line 127
at c:/perl/lib/text/csv.pm line 23
can't locate object method "new" via package
"text::csv" at test1.pl line 4
------------------------
My script is called test1.pl and I am running it via a bat file.
Thanks for reading this in an attempt to assist!!!!
tmh