×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

help me parse a csv file

help me parse a csv file

help me parse a csv file

(OP)
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

RE: help me parse a csv file

You need to add the library to your @INC.  do this:

use lib wherever_the_Lib_is

at the begining of the script Hope that gets it


Miah

RE: help me parse a csv file

(OP)
I don't understand how to do that.  I am just a beginner.  I have continued to research this and I think one of my problems is that I don't have the Text::CSV module installed.  I found it on CSPAN, but can't figure out how to properly install it.  I am running a Win32 system.  I would like to be able to use the quick install that is offered on CSPAN, but I can't seem to make it work.  Any assistance is greatly appreciated.  Thanks.

Michelle

RE: help me parse a csv file

Okay I don't use Win32, I use Solaris, but let me see here there are a few basics.  Know where you want to put it I put them in /opt/local/lib/perl5/5.00502, so I would look for where your win32 perl is and then the modules should be around there, and put it there.  Unzip it and tar it, if you do not have the correct tools checkout http://www.aladdinsys.com/expander/expander_win_login.html

Then use the README/INSTALL.  it should tell you to do

perl Makefile.PL
make
make test
make install

That should be it.  It is a little overwhelming but it is easy to install modules

Miah

RE: help me parse a csv file

(OP)
Thanks Miah.

I had to download nmake.exe and nmake.err from microsoft's ftp server.  It came in the form of nmake15.exe.  After I did that, the nmake works the same as the make.  I put the nmake.exe and nmake.err in my path and then downloaded the modules I wanted.  I put the module in a seperate temp folder and extracted the files from the tr file.  After that, I went to the temp directory from my DOS shell and ran the commands you recommended above. Only I used nmake in place of make.

Thanks for pointing me in the right direction.

Michelle

I finally figured it out.  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close