1

I am currently trying to create/generate a CSV file using one of three classes:

use Class::CSV;
use Text::CSV;
use Text::CSV_XS;

Though when I try and run it, to check my code I come up with the same error message:

Can't locate Class/CSV.pm in @INC (@INC contains: C:/Per/site/lib C:/Perl/lib .) at C:\Users\<DIRECTORY> - <DIRECTORY>.file.pl line1

I have tried searching for the files though I haven't had any luck. Has anyone else come up against this problem? I have looking in the Directory and the CSV.pm file does exists.

QuinsUK
  • 361
  • 2
  • 5
  • 14

3 Answers3

5

You probably don't have these modules installed.

run this in your shell

perl -MCPAN -e shell

then run

install Class::CSV

I'm assuming that you found these classes on CPAN

fedorqui
  • 275,237
  • 103
  • 548
  • 598
John Corbett
  • 1,595
  • 10
  • 19
  • Yes I did get these classes on CPAN, all the others worked, apart from this classes for some reason. – QuinsUK Aug 02 '12 at 15:09
  • Do you then run all your Perl scripts through this now?? What does this do?? – QuinsUK Aug 02 '12 at 15:12
  • are you sure it installed correctly? Try installing again to see if CPAN recognizes the modules as installed. – John Corbett Aug 02 '12 at 15:13
  • Installing the @INC environment again or just unzipping the class files again? – QuinsUK Aug 02 '12 at 15:22
  • try installing the CPAN module again, and see if it tries to. If it tries to install the module again, it didn't install correctly the first time, otherwise it will tell the that it's installed properly and give you a version number. I'll bet that it didn't install properly because you can't find the files and you're getting an @INC error. – John Corbett Aug 02 '12 at 15:25
5

Assuming that Class::CSV is installed on your system, your library search path is incomplete. (Your error message lists C:/Per/site/lib as a search lib, which looks like a typo for C:/Perl/site/lib, which you might want to look into.)

You need to locate the correct CSV.pm file where the library is located. For example, if it's found in:

C:/Perl/lib/foo/Class/CSV.pm

Then you have one of the following options.

  1. Modify the environment for Perl or the invocation so that this is set (assuming my Windows skill haven't expired completely, someone feel free to edit and correct if I get the syntax wrong):

    PERL5LIB=%PERL5LIB%;C:/Perl/lib/foo
    
  2. You can use the -I option to perl to add the path:

    perl -IC:/Perl/lib/foo my-app.pl
    
  3. You can use the use lib command in the program itself to add the search path:

    use lib 'C:/Perl/lib/foo';
    use Class::CSV;
    # etc.
    
zostay
  • 3,985
  • 21
  • 30
  • Thank you, I am new to Perl, so I am trying to figure all this out. – QuinsUK Aug 03 '12 at 14:18
  • 1
    No problem. I like to help. Unfortunately, not all the Perl hackers out there (or even on this site) have the patience to deal with someone trying to figure it out. I commend you to Perl and staying the course. I think you'll find it rewarding to use. Cheers. – zostay Aug 03 '12 at 15:48
0

You can simply run the following command

perl -MCPAN -e 'install Class::CSV'

to run install Class::CSV in CPAN shell.

rasboy
  • 1