Perl Makes Life Easier

By: Deva Nullkowska

Perl is wonderful interpreted, cross platform, very high level, powerful language which will make your life much easier.
You need to sort your files? Mass rename your files? Find certain string from multiple files? Need to automate web queries? Then Perl is your best friend. Some may argue that Perl is hard to learn and/or its syntax is ugly/hard to read. That is not entirely true. It's just that there is too much "bad" Perl around the internet which causes confusion and misconceptions about the language. Here are few tips on how to write clean, understandable Perl;
1. Use lexical variables
2. Subroutines are your friend
3. Never ever quote numbers
4. Have perldoc perlretut and perldoc perlreftut open at all times
5. Use CPAN modules, don't reinvent solutions

The purpose of this article is not to get you started in 3 minutes with Perl, but show how useful Perl can be for everyday tasks which will save you hours of manual work.
I love Perl one-liners, you write them in seconds but they save hours of work if done by hand.
For example if you wish to replace a string in a file
perl -wipe 's/string_that_needs_to_go/new_string/' file.txt
Or you want to parse all IPs from apache access_log file
perl -wlne 'print $1 if m/(d{1,3}.d{1,3}.d{1,3}.d{1,3})/' access_log

Perl regular expressions may appear hard and confusing but they make perfect sense and perldoc perlretut makes that sense. Trust me regular expressions will make your everyday tasks much easier.

If you invest one hour a day to Perl, Perl will save you a lot more time in future, and everyone knows time is money.
The books I recommend to start with Perl is Learning Perl 4th edition by Randal-Schwartz, Programming Perl 3rd edition by Larry Wall (the creator himself) and Perl Cookbook 2nd edition by Tom Christiansen (my favorite). All of these books are available in numerous places, shouldn't take much effort to find them.

CPAN offers us a lot of modules to solve complicated problems. Just check search.cpan.org and browse through millions of modules for just about anything. The LWP module is an awesome module for simple web automation, however when things go complicated WWW::Mechanize is here to save the day.
Some of us like our programs to be good looking and user friendly. Well Perl can offer you that too, with its Perl/Tk extension. With a little bit effort you can make your command-line scripts look and feel great.

Perl is installed on most *NIX operating systems for a reason. However if you're a windows user there are alternatives. Like I said Perl is cross platform and it can be installed on just about any operating system out there. For windows users I suggest Strawberry Perl. If you use cygwin then it's probably a good idea to install their Perl port.

Perl is also awesome for CGI scripts. It comes with a lot of HTML modules like HTML::Mason and HTML::Template to manipulate HTML with just few lines. The CGI module of course is mandatory for any half-decent Perl-CGI script.
Don't go parsing HTML using regular expressions, HTML::Parser will not only make it easy, but your scripts will look much better and someone else would be actually able to read them.

Perl is wonderful, I've been using it for years and I love it. I'm sure if you give it a little time you'll love it in no time.
There is tons of online help/support for Perl. Even though Perl is very well documented, sometimes you need directions and advice from experts.
The IRC channel on irc.freenode.net #perl is the place to seek help but after you tried everything you could think of and consulted with perldoc and google.

Programming
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Programming
 



Share this article :
Click to see more related articles