IT DRILLDOWN
 
NEWSLETTERS
 

CIO.com updates, insights and advice on technology, management and your career.

 Advice and Opinion

 CIO Consumer IT

 CIO Leader

 CIO Enterprise

 CIO Insider

 

RSS Feeds »

 
 
LEADERSHIP
 

CIO Executive Programs

The Leader in Face-to-Face Education for Senior Executives

Offering regional and national programs, CIO (and CSO) events bring together some of the most respected names and thought leaders in information technology and security. Presented by CIOs and other senior level executives, these invitation-only programs offer timely topics and strong networking. Learn More »

 

CIO Executive Council

Public Teleconferences

Join CIO Executive Council members and participate in the following live teleconferences:

* Planning for Succession:
Models for IT Leadership Development, June 23
* Youth in IT: How CIOs Can Engage the Next Generation
June 10
* Change Leadership at General Growth Properties: A
Pathways Leadership Development Seminar, June 25

More / Register »

Learn more about the CIO Executive Council »



 
 
RESOURCE CENTER
 
 
 
SUBSCRIBE TO CIO
 

Are you involved in setting the direction for your company's IT budget or strategy?


Apply today for a FREE subscription to CIO Magazine!

Subscription Services »

Reprints »

 
 

Feature

 

You Used Perl to Write WHAT?!

Every programming language has its strengths...and its weaknesses. We identify five tasks for which perl is ideally suited, and four that...well, really, shouldn't you choose something else?
 

PAGE 2

Not So Good: Beware

Just like there are places where perl is a great fit, there are some uses that just aren't right. Here are a few potential applications that should make you run screaming into the night.

  1. Real-time or high-performance applications: Perl is an interpreted language. In general, interpreted languages are not known to be speed demons. In researching this article, the most glaring example I found of someone who took perl to a place it didn't want to go was a gentleman who decided to implement a ray-tracing program for 3-D computer graphics in perl. Even he admits it was a perverse thing to do!

    When looking at a potential application, if it seems to be characterized by a lot of tight loops over intensive calculations, you should probably be looking elsewhere.

    Similarly, if the application is dependent on real-time response (especially life-critical or mission-critical response), perl won't give you those kind of performance assurances, at least out of the box.

  2. As a replacement for shell scripts: "But wait!" you scream, "You just told me I should be using perl to replace shell scripts." And you should—if you do it right. Consider these two sample scripts:

    @files = `ls .`;
    for $file (@files) {
       system("cp $file $file.bak");
    }

    versus:

    use File::Copy;

    opendir(DIR, ".");
    @files = readdir(DIR);
    close(DIR);

    for $file (@files) {
       if ($file =~ /.doc$/) {
            copy($file, "$file.bak");
       }
    }

    There's no question that the second version is longer. However, the first version will fork a subshell to do the ls, and then a subshell every time it moves a file. The second version never needs to fork a shell (which is memory- and performance-wasteful). I've seen perl scripts that are nothing but a series of system calls to shell commands.

    Sometimes you can't get around using a system or backtick command in a perl script, but whenever possible, use the native functionality that mimics the shell call you'd otherwise make. This has the additional benefit of making the script portable. The first version of our sample script won't run on Windows, while the second one works on both Linux and Windows.

  3. As a Web scripting language: One of the earliest usages of perl, as the Web evolved, was for CGI programming webpages. As a result, perl has some pretty strong packages for dealing with Web forms. There is also support for embedding perl into HTML in the same way the Java is embedded into JSP pages.

    However, I would argue that more modern Web scripting languages, such as PHP and Ruby on Rails, offer more out-of-the-box Web support and a cleaner integration into the webpage experience. You should especially avoid using perl for traditional CGI-style form processing; this code tends to be hard to read and maintain because the HTML ends up inlined inside the perl code.

  4. In an obfuscated fashion: Larry Wall, creator of perl, famously stated, "Perl is designed to give you several ways to do anything." As a result, some developers have adopted the style of writing their code as compact and "elegantly" as they can. The results can sometimes be programs that look more like dialup line noise than supportable code.

    Remember that the full version of Wall's quote states, "Perl is designed to give you several ways to do anything, so consider picking the most readable one." Break up long lines into several statements, store intermediate values rather than passing them down a long chain of functions and use comments and whitespace to make the code clear.

 
 
 
 
 
 
Loading...
 
 
ABCs
 

How To Do Nearly Anything

Just the basics, please. Sometimes we all need a refresher or we need to make sure our team and our colleagues are all on the same page.

Over 25 tutorials on everything from business intelligence to virtualization.

 
 
FEATURED SPONSORS
 
 
 
SPONSORED LINKS
 

Enterprise Service Bus: A Definition

Model, Execute, and Optimize: Oracle Fusion Middleware and the BPM Lifecycle

Case Study: Customer Integration Wins at Invitrogen

Internet's Largest Book Retailer Scores Big with B2B Customers

Establishing a Strategy for Global Distributed Development

Drive More Effective Business Processes with SOA

Fuel the Responsive Enterprise Through Oracle Fusion Middleware

Oracle 9i Database Upgrade Management Services - Upgrade with Confidence

Extending the Enterprise Network Through Mobility

Global Crossing is the most viable alternative for voice, video and data.

The New Foundation of Storage: Xiotech's Intelligent Storage Element

BPM Done Right: 15 Ways to Succeed Where Others have Failed

3 Reasons to Invest in Integration Technology Now

A CIO's View of Server Virtualization

Let's Get Virtual: A Look at Today's Server Virtualization Architectures

Increase conversions on your site with the help of EV SSL.

Get Control of Mobile Data (and More)

Data Loss Prevention Starts at the Endpoint

Building a Foundation for Pragmatic Service Management White Paper

Performance Brief: Mobile Application Acceleration

Strategies for centralizing data backup

Citrix XenServer FREE trial

Nothing Short of Revolutionary: Four Steps toward More Effective Enterprise Finance

The Best IT Strategy for a Company with Global Operations

Speed, agility, flexibility - The HP BladeSystem c-Class

White Paper: Assess Your SOA

People, Processes, and SOA: Oracle Fusion Middleware and the Responsive Enterprise

Learn about B2B integration for Companies of All Sizes

Integration as a Service Webcast: Are you connected?

BEA & Forrester Webcast: "The Enterprise 2.0 Workplace." Register Now!

Balance Your Innovation and Efficiency Platforms for Competitive Advantage and Responsiveness

Oracle & SUN Team to Rise Above the Upgrade Challenge

Learn how to communicate the business value of IT

White Paper: Learn how to succeed with BPM

Webcast: Research insight into how organizations are using virtualization

ITIL V3 and the IT Service Catalog

The New Growth Paragidm: Multi-Enterprise SOA

3M saved $3M on printing. Learn how HP can help your business

Survival of the Fittest: Disaster Recovery Design for the Data Center

Windows Server 2008: To Upgrade or Not to Upgrade?

How Office 2007 Exposed Bill Gates

How to simplify mobility and reduce the cost of supporting mobile workers

Helping IT Become a Service Provider White Paper

Extending PCI Compliance to the Mobile Workforce

A proven approach to WAN optimization

Wireless Vulnerability Management: What It Means for Your Enterprise

Green IT: Reducing Your Carbon Footprint with Citrix

Wide-area data services enable todays global enterprise

Discover PMI's credentials and career path tools

Symantec State of the Data Center Report