Datamation Logo

Make Perl Scripts More Readable With perltidy

October 2, 2008
Datamation content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

I am of course sure that everyone reading this is well aware of scripting best practices and always writes beautifully neat and well-set-out scripts that will still have meaning when you return to them in six
months time. You might not then need perltidy for your own
scripts.

Even so, from time to time you might come across a script left
over from before your time or written by a colleague in a hurry that on
examination bears a strong resemblance to alphabet spaghetti.

Enter perltidy, a program generated from the Perl module
Perl::Tidy, which saves you time by unmangling Perl code for you. You can
download it from CPAN, or it may be available through your distro. (Debian and
Ubuntu both provide it.)

Basic operation is simply to type perltidy badscript.pl. This
will leave the initial file alone and create a new tidied-up file with a
.tdy extension.

Alternatively, you can use the -b switch to do the opposite: Make a backup of the original file and then edit it in-line. The -syn switch will run a syntax check of the original code at the same time.

I tried it out on the second
prize entry in the 5th annual Obfuscated Perl Contest
. Although it didn’t simplify the program logic any, it definitely made it more
readable and gave a better chance of figuring out what was going on. Try it
out for yourself, and see if it can save you some time and mental effort in
disentangling confusing code.

This article was first published on ServerWatch.com.

  SEE ALL
ARTICLES
 

Subscribe to Data Insider

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more.

Datamation Logo

Datamation is the leading industry resource for B2B data professionals and technology buyers. Datamation's focus is on providing insight into the latest trends and innovation in AI, data security, big data, and more, along with in-depth product recommendations and comparisons. More than 1.7M users gain insight and guidance from Datamation every year.

Advertisers

Advertise with TechnologyAdvice on Datamation and our other data and technology-focused platforms.

Advertise with Us

Our Brands


Privacy Policy Terms & Conditions About Contact Advertise California - Do Not Sell My Information

Property of TechnologyAdvice.
© 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.