Perl Commands

perl

What are some interesting perldoc that I still need to read?

perldoc perldoc
perldoc perl
perldoc perlstyle
perldoc perlvar
perldoc perldsc
perldoc perllol

How can we install a Perl module from CPAN?

perl -MCPAN -e 'install Digest::SHA'
cpan install URI

How can we upgrade all of your installed modules?

perl -MCPAN -e 'upgrade'

How can we quit the CPAN shell?

quit

How can we use a module from command line??

perl -MLWP::Simple -e 'print head "http://www.example.com"'

The -M switch is the same as 'use module'. If the module has default import that you don't want imported, the you can use -m switch (equivalent to 'use module ()') which turn off any default import. Any arguments you would normally pass to the use statement can be listed following an = sign:

perl -MCGI=:standard -e 'print header'

This command imports the ":standard" export set from CGI.pm and therefore the header function becomes available to your program. Multiple arguments can be listed using quotes and commas as separators:

perl -MCGI='header,start_html' -e 'print header, start_html'

How can we see if URI.pm is installed?

perl -MURI -e 1

How can we print the version number of a module?

perl -MDBD::mysql -e 'print $DBD::mysql::VERSION'
perl -MDBI -e 'print $DBI::VERSION'

How can we find which version of Perl is install?

perl -V

How can we find where URI.pm is on the system?

perldoc -l URI

How can we display the content of a file?

perldoc -F filename

How can we display the documentation for open()?

perldoc -f open

How can we search perlfag?

perldoc -q shuffle

How can we view the source of a module?

perldoc -m Test::MockObject

How can we install a module into a non-standard, user-specific location?

mkdir -p ~/perl5lib
perl Makefile.PL PREFIX=~/perl5lib
// or perl Makefile.PL LIB=~/perl5lib
make
make install
export PERL5LIB=$PERL5LIB:~/perl5lib

To use modules that are installed in your home directory, specify the -I switch:

perl -I/home/khai/lib/perl -T 00-load.t

The -I switch tells Perl to look for modules in alternate installation directory. The directory path must immediately follow the -I switch with no space in-between.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License