Please send corrections via the contact page.
% perldoc perldoc
% perldoc perlfaq
% perldoc perlfaq1
% perldoc perlcheat
or search for one
% which perl
/usr/bin/perl
% vi myscript.pl
#!/usr/bin/perl
# print Content-type for the web
print "Content-type:text/plain\n\n";
print "123";
print qq~
this is a test
~;
% chmod u+x myscript.pl
or on your website:
% chmod 755 myscript.pl
% perl -c myscript.pl
myscript.pl syntax OK
% ./myscript.pl
123
this is a test
Include this in your Perl script, based on the sample CPAN shell usage below.
use lib "/some/where/myperl/lib";
The CPAN shell is by far the easiest way I know of to manage modules but the initial configuration can be a little bit of a hassle. The first thing I recommend is using the CPAN shell to upgrade CPAN to the latest version. Here is a rundown of how to start CPAN and use it to do this (commands start with '%' or 'cpan>' and my comments don't).
First I setup a folder in my home directory for the Perl modules:
% mkdir myperl
Then I set the PERL5LIB environment variable so that Perl knows
where I keep my Perl modules and checks there first. I use tcsh
and vi. You could use pico instead of vi and replace setenv with
export if you use Bash (and edit the appropriate rc files):
% vi .cshrc
adding these lines to the file:
setenv PERL5LIB ~/myperl/lib
setenv MANPATH ~/myperl/share/man
I can confirm this looks right by doing:
% source .cshrc
% perl -V
Now I start up CPAN from the command line:
% perl -MCPAN -e shell
Walk thru the dialogs to initialize your settings: they are very simple and have recommendations with explanations. If anything goes wrong you can simply finish the setup and change the settings later by editing (or deleting) the config file (at ~/.cpan/CPAN/MyConfig.pm) or by using "cpan> o conf SETTING" in the cpan shell.
Next I check the current version of CPAN:
cpan> m Bundle::CPAN
And then installed the latest version:
cpan> install Bundle::CPAN
When finished it gives the status of the install so I
exit CPAN and restart it with:
cpan> exit
% perl -MCPAN -e shell
Because I am in the habit of using CPAN I had problems figuring out the initial configuration. There are 2 common ways of building modules: MakeMaker/Makefile.PL and Module::Build/Build.PL. These use separate settings "makepl_arg" and "mbuildpl_arg" (stored in MyConfig.pm). Because I am installing modules to a non-standard location I have to provide these utilities with this info, otherwise they won't know where to install. These are the settings I used in MyConfig.pm:
% vi .cpan/CPAN/MyConfig.pm
'makepl_arg' => q[LIB=/home/jim/bin/perl/lib INSTALLMAN1DIR=/home/jim/bin/perl/share/man/man1 INSTALLMAN3DIR=/home/jim/bin/perl/share/man/man3],
'mbuildpl_arg' => q[--install_path lib=/home/jim/bin/perl/lib --install_base /home/jim/bin/perl --destdir /home/jim/bin/perl --prefer_installer MB],
For more info on these details see: perldoc CPAN or man CPAN, CPAN.pm Configuration and Examples of Module::Build Usage