Programming‎ > ‎

Perl

Perl Tips

Here are Perl tips.

Index


How can I set the module path for Perl ?

This is a real pain if you are not a root so that modules cannot be put in the default place /usr/lib/perl5 .....First check the module path by (note that RedHat installs it in /usr/lib/perl5)

   
  $ perl -e 'print "@INC\n"'  
  /usr/lib/perl5/5.8.0/i386-linux-thread-multi    
  /usr/lib/perl5/5.8.0    
  /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi    
  /usr/lib/perl5/site_perl/5.8.0    
  /usr/lib/perl5/site_perl    
  /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi    
  /usr/lib/perl5/vendor_perl/5.8.0    
  /usr/lib/perl5/vendor_perl    
  /usr/lib/perl5/5.8.0/i386-linux-thread-multi    
  /usr/lib/perl5/5.8.0
  

One way is to set the environmental variable PERL5LIB.


  csh:   
  $ setenv PERL5LIB where_pathbash:   
  $ export PERL5LIB="where_path"
  

Another way is to point the module location in perl script itself.

   
  use lib 'where_path';
  

Top


How can I get a new module from internet?

I was told by a perl lib not to be able to find Text::Format module. I used CPAN to do this job.

  
  # perl -MCPAN -e shell  
  /usr/lib/perl5/5.8.0/CPAN/Config.pm initialized.  
  CPAN is the world-wide archive of perl resources. It consists of about  
  100 sites that all replicate the same contents all around the globe.  
  Many countries have at least one CPAN site already. The resources  
  found on CPAN are easily accessible with the CPAN.pm module. If you  
  want to use CPAN.pm, you have to configure it properly.  If you do not 
  want to enter a dialog now, you can answer 'no' to this  
  question and I'll try to autoconfigure. (Note: you can revisit this  
  dialog anytime later by typing 'o conf init' at the cpan prompt.)  
  Are you ready for manual configuration? [yes] no  ....(omitted)  
  commit: wrote /usr/lib/perl5/5.8.0/CPAN/Config.pm  
  cpan shell -- CPAN exploration and modules installation (v1.61)  
  ReadLine support available (try 'install Bundle::CPAN')  
  cpan> install Text::Format  
  CPAN: Storable loaded ok  
  CPAN: LWP::UserAgent loaded ok  
  Fetching with LWP:    ftp://ftp.perl.org/pub/CPAN/authors/01mailrc.txt.gz  
  Going to read /root/.cpan/sources/authors/01mailrc.txt.gz  
  Fetching with LWP:    ftp://ftp.perl.org/pub/CPAN/modules/02packages.details.txt.gz  
  Going to read /root/.cpan/sources/modules/02packages.details.txt.gz    
  Database was generated on Mon, 09 Aug 2004 13:06:20 GMT    
  There's a new CPAN.pm version (v1.76) available!    
  [Current version is v1.61]    
  You might want to try      
  install Bundle::CPAN      
  reload cpan    
  without quitting the current session. It should be a seamless upgrade    
  while we are running...  
  Fetching with LWP:    ftp://ftp.perl.org/pub/CPAN/modules/03modlist.data.gz  
  Going to read /root/.cpan/sources/modules/03modlist.data.gz  
  Going to write /root/.cpan/Metadata  
  Running install for module Text::Format  
  Running make for G/GA/GABOR/Text-Format0.52.tar.gz  
  Fetching with LWP:    ftp://ftp.perl.org/pub/CPAN/authors/id/G/GA/GABOR/Text-Format0.52.tar.gz  
  CPAN: Digest::MD5 loaded ok  
  Fetching with LWP:    ftp://ftp.perl.org/pub/CPAN/authors/id/G/GA/GABOR/CHECKSUMS  
  Checksum for /root/.cpan/sources/authors/id/G/GA/GABOR/Text-Format0.52.tar.gz ok  
  Scanning cache /root/.cpan/build for sizes  
  Text-Format0.52/  
  Text-Format0.52/lib/  
  Text-Format0.52/lib/Text/  
  Text-Format0.52/lib/Text/Format.pm  
  Text-Format0.52/MANIFEST  
  Text-Format0.52/README  
  Text-Format0.52/Makefile.PL  
  Text-Format0.52/Changes  
  Text-Format0.52/t/  
  Text-Format0.52/t/justify.t  
  Text-Format0.52/t/format.t  
  ...(omitted)  
  Running make install  
  Manifying blib/man3/Text::Format.3pm  
  Installing /usr/lib/perl5/site_perl/5.8.0/Text/Format.pm  
  Installing /usr/share/man/man3/Text::Format.3pm  W
  riting /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/auto/Text/Format/.packlist  
  Appending installation info to /usr/lib/perl5/5.8.0/i386-linux-thread-multi/perllocal.pod    
  /usr/bin/make install  -- OK  
  cpan>
  

Top

Home

Updated 8/9/2004