Perl makes life easier
- Date: 2007-10-08 - Word Count: 610
Share This!
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.
About the Author:
Deva Nullkowska is a freelance webmaster working only on interesting projects Visit her blog here
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.
About the Author:
Deva Nullkowska is a freelance webmaster working only on interesting projects Visit her blog here
Related Tags: perl, cgi, regex, regular expressions, web autmation
Your Article Search Directory : Find in Articles
Recent articles in this category:
- Improper Way Of Marketing Reflects Poorly On A Company.
New business, product or service everything requires visibility, awareness in order to come into the - Replacing Paper Prints With Online Versions
Nowadays saving out on resources and being additionally informative are both aspects that are in. In - Stop Smoking Effectively
If I told you of a way that you could stop smoking harmful tobacco would you believe it? Most people - What Is Runtime Error 182? And How To Fix It
Are you finding an effective way to fix runtime error 182? Do you think fixing runtime error 182 is - Do You Know How To Fix Runtime Error 87 In Minutes?
Are you finding an effective way to fix runtime error 87? Do you think fixing runtime error 87 is to - Knowledge About Avi, Avi Player, Avi Converter On Mac
Knowledge about AVI, AVI player, AVI Converter on MacWhat is an AVI?AVI, an acronym for Audio Video - Buy Your Highly Successful Email Survey Software Today
Email Survey Software- Boost Your Business and Increase ProfitsAn email survey software could be one - Xrm - The Anything Relationship Management Solution
I recently attended the Microsoft Dynamics West Region FY11 Sales Planning Retreat. This year's meet - What Are The Benefits Of Working With Electronic Medical Records
Recording medical information is a vital part of health care services. These records are necessary f - Basic Factor To Make Website Business Oriented
Internet is home for millions of websites. The online business is becoming more and more competitive
Most viewed articles in this category:
- Parental Control Software
Parental control software is software that can help parents protect their children when they are onl - Digital Asset Management Software
Managing and organizing your organization's documents is a critical component to your business's suc - AdobeRGB vs. sRGB
Understanding color spaces I'll try to explain it very simplified, but understandable for everyone - Confessions of a Prankster
I wanted to get a jump on April Fool's Day, partially because of the long, cold winter blues, and pa - Malicious Thoughts About The Spyware Ills Of My PC
Who would think I was capable of such revengeful thoughts about the parties responsible for inflicti - Recover File and Recover Deleted File Tools
Data recovery software is a very effective way of retrieving data from a worn or damaged hard disk d - Life without Windows
Ubuntu, a user-friendly version of Linux, has been running so nicely on my home PC that I decided to - What Benefit Does an Online Software Download Site Offer You?
Are you having a problem that where you find a good softeware when you consider to have a try or wan - Maintaining A Website
There was an era when people were talking about how to create a website using html coding or some ea - Benefits Of Proper Time Tracking
Have you ever written down time when you have started and finished your work? Maybe you have had mul