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

Wednesday, November 5, 2008

To get current date and time. hh:mm::ss mm/dd/yy

To get the current date and time in the format hh:mm::ss mm/dd/yy and if you are looking for a perl one liner here you go.

perl -e "use POSIX; print strftime qq(%X %x), localtime(time); "

Output is

00:00:51 11/06/08

Tuesday, November 27, 2007

One Liner : List all files of a directory.

If one wants to list all the files and directories from a particular directory here is the onliner for the same. We use IO::ALL for this purpose in this post.

perl -MIO::All -wle "my $io = io('e:/downloads'); print $io->All;"

and the output will list all the directories and files in downloads folder.

Comments and other ways are alwayz a welcome.

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.