Search your unanswered perl queries
Google
Showing posts with label perl modules. Show all posts
Showing posts with label perl modules. Show all posts

Thursday, October 30, 2008

Getopt::Long :s option specifier

: s option of getopt::long come very much handy when one is looking for the following requirement

1) If a command line option is passed a paramter it is taken as a value for the given option

i.e perl program -option1 value1

$option1 will take value1.

2) If a command line option is not mentioned then variable remains undefined.

i.e perl program

$option1 will remain undef.

3) If a command line option is mentioned but paramter is not passed, then a empty string will be assigned to $option if :s is used and 0 if :i is used

i.e perl program -option1

$option will be q{}... an empty string.

Please take a look at http://search.cpan.org/dist/Getopt-Long/lib/Getopt/Long.pm for further information.

Friday, November 16, 2007

Perl Module : How to Install Perl Module on Windows

The most simple task to make your tasks simpler is installing a perl module on your machine.
There are three common ways by which one can install a perl module on your machine. Lets see the installation on windows machine in this post.

There is a ppm utility provided with every active state perl installation, atleast I got it with perl Vesion 5.8.X All you have to do is follow the below steps

1) Click Start
2) Click Run
3) Type cmd and press enter
4) Type ppm and press enter
5) Once you get the ppm utility prompt like ppm> type install modulename
eg. install Net::SSH::Perl
The ppm utility will carry the installation of the perl module for you.

There is workaround for this if you don't have ppm utility or want to install the module manually. Download the zip file from cpan and unzip it with unzip utitliy. Go to the respective directory on command prompt and enter the following commands in sequence.

1) c:\>Net-SSH-Perl>perl Makefil.PL
2) c:\>Net-SSH-Perl>nmake
3) c:\>Net-SSH-Perl>nmake test
4) c:\>Net-SSH-Perl>nmake install

And the module will be installed for you.

Do comment on how you install the new perl modules.

Tuesday, November 13, 2007

One Liner : To check if a module is already installed

I have always came at this stop where i needed to check if a module is already installed or if so what is the version of the module.

perl -e "use [modulename]" e.g perl -e "use Net::SSH::Perl" will tell you if the module is installed or not. If its installed nothing happens and you get the prompt to perform new task. If it is not installed perl throws an error somewhat like can't locate Net/SSH/Perl.pm

perl -M[modulename] -e "print $[modulename]::VERSION" will print the current version of the module. e.g perl -MCGI -e "print $CGI::VERSION"
Most of the packages has a package variable as VERSION which holds the version of the module.

However the only true way to determine if a module is correctly installed, one can run the test scripts provided in the t folder of the module distribution. If all the scripts can run successfully, then only one can be sure that a particular module is installed fully or properly.

Do let us know what method do you use to see if a perl module is installed on your machine.