Thursday, 22 December 2011

Perl: Can't locate [Library Here] in @INC - (CPAN Usage)


So i've been looking into Perl this week and I came across an error... quite simple when you know how... this post explains in !English! the options you can take to tackle this... CPAN is utilised and explained in this post.


The Error
SeanMAC:tmp localhome$ perl test.pl
Can't locate SOAP/Lite.pm in @INC (@INC contains: /Library/Perl/Updates/5.8.8/darwin-thread-multi-2level /Library/Perl/Updates/5.8.8 /System/Library/Perl/5.8.8/darwin-thread-multi-2level /System/Library/Perl/5.8.8 /Library/Perl/5.8.8/darwin-thread-multi-2level /Library/Perl/5.8.8 /Library/Perl /Network/Library/Perl/5.8.8/darwin-thread-multi-2level /Network/Library/Perl/5.8.8 /Network/Library/Perl /System/Library/Perl/Extras/5.8.8/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.8 /Library/Perl/5.8.6 /Library/Perl/5.8.1 .) at test.pl line 17.
BEGIN failed--compilation aborted at test.pl line 17.



So I created a test script and attempted to execute it. It threw up an error at Line 17 complaining that I didn't have the SOAP::Lite library. I.e. "Can't locate SOAP/Lite.pm"

In .NET we would probably either Google the library or use NuGet (NuGet.org - NuGet is a Visual Studio extension that makes it easy to install and update open source libraries).

If we would ever try to compare Perl to the .NET world, we could relate CPAN to NuGet in terms of what it does for us. That is, gets third party libraries, unpacks them and installs them for us.


CPAN
CPAN, the Comprehensive Perl Archive Network, is an archive of over 100,000 modules of software written in Perl, as well as documentation for it.

To use cpan, open up a terminal or command window, and use the following command. This will run cpan as ROOT user. This is sometimes necessary as it requires access to shared library directories.
Code Snippet
  1. perl -MCPAN -e 'shell'
End of Code Snippet

You will then be in the cpan shell. Type 'h' for help....

commandargumentdescription
a,b,d,mWORD or /REGEXP/ about authors, bundles, distributions, modules
iWORD or /REGEXP/ about anything of above
rNONEreinstall recommendations
lsAUTHORabout files in the author's directory
getdownload
makemake (implies get)
testMODULESmake test (implies make)
installDISTS, BUNDLESmake install (implies test)
cleanmake clean
lookopen subshell in these dists' directories
readmedisplay these dists' README files


If we wish to install our library (This includes get/download, make, test and install) then we simply issue the command....
Code Snippet
  1. install [Library Name]
End of Code Snippet

with example
Code Snippet
  1. install SOAP::Lite
End of Code Snippet

You will be asked a few options, mostly regarding ideal location to download from, connection timeouts etc... You can simply keep hitting enter to use the defaults.

If all is successful, your library will be installed and included within the @INC array (Containing paths to libraries used by Perl).

Happy Scripting!

1 comment:

Anonymous said...

Thanks, this has helped me!