Book Home Programming PerlSearch this book

Chapter 24. Common Practices

Contents:

Common Goofs for Novices
Efficiency
Programming with Style
Fluent Perl
Program Generation

Ask almost any Perl programmer, and they'll be glad to give you reams of advice on how to program. We're no different (in case you hadn't noticed). In this chapter, rather than trying to tell you about specific features of Perl, we'll go at it from the other direction and use a more scattergun approach to describe idiomatic Perl. Our hope is that, by putting together various bits of things that seemingly aren't related, you can soak up some of the feeling of what it's like to actually "think Perl". After all, when you're programming, you don't write a bunch of expressions, then a bunch of subroutines, then a bunch of objects. You have to go at everything all at once, more or less. So this chapter is a bit like that.

There is, however, a rudimentary organization to the chapter, in that we'll start with the negative advice and work our way towards the positive advice. We don't know if that will make you feel any better, but it makes us feel better.

24.1. Common Goofs for Novices

The biggest goof of all is forgetting to use warnings, which identifies many errors. The second biggest goof is forgetting to use strict when it's appropriate. These two pragmas can save you hours of head-banging when your program starts getting bigger. (And it will.) Yet another faux pas is to forget to consult the online FAQ. Suppose you want to find out if Perl has a round function. You might try searching the FAQ first:

% perlfaq round
Apart from those "metagoofs", there are several kinds of programming traps. Some traps almost everyone falls into, and other traps you'll fall into only if you come from a particular culture that does things differently. We've separated these out in the following sections.

24.1.1. Universal Blunders

24.1.2. Frequently Ignored Advice

Practicing Perl Programmers should take note of the following:

24.1.3. C Traps

Cerebral C programmers should take note of the following:

24.1.4. Shell Traps

Sharp shell programmers should take note of the following:

24.1.5. Previous Perl Traps

Penitent Perl 4 (and Prior) Programmers should take note of the following changes between release 4 and release 5 that might affect old scripts:



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.