in reply to Perl aesthetics: the good, the bad, the ugly.

Here's my horrible confession. We often hear that you can program Perl to resemble your favorite programming language/style. C-style for loops are the classic example:

for ( my $i = 0; $i < @array; $i++ ) { ... }

We're admonished to avoid that, if possible, due to classic "off by one" errors.

my @array = qw/ zero one two three four /; for ( my $i = 0; $i < $#array; $i++ ) { print $array[$i],$/; }

LISP programmers appreciating the aesthetics of the Schwartzian Transform is another example.

Confession time: I used to be a COBOL programmer. Oh, I used strict, warnings, taint checking, and whatever else I thought was "good", but I had a bad habit of writing my subroutines "COBOL-style", with the exception of passing in the arguments.

sub foo { my $arg = shift; foreach my $data ( @data ) { $bar[ $data ] += $arg; } }

I know better now, but it took me a long time to see the error of my ways :(

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.