Re: Curly braces and the logic of PERL
- From: Jenda@xxxxxxxxxxx (Jenda Krynicky)
- Date: Wed, 29 Oct 2008 11:35:56 +0100
From: Rob Dixon <rob.dixon@xxxxxxx>
I have a particular issue with statements like
/\Q$string/ && print $REPORT "$File::Find::name\n" and return;
which are ugly in the extreme and do not begin to read as English. The style
comes from Perl's origins on the Unix platform, and use of shortcuts like this,
that are familiar to Unix shell programmers, do nothing to help Perl's migration
to other platforms. The grep() function is a similar culprit - thank God there
is no sed() or awk().
I'd probably write that as
print $REPORT "$File::Find::name\n" and return if /\Q$string/;
or
if (/\Q$string/) {
print $REPORT "$File::Find::name\n";
return;
}
The first reads as English to me just fine.
OTOH, grep{} is a totally different thing. And
my @even = grep {$_ % 2 == 0} @numbers;
is definitely easier to validate than
my @even;
for (@numbers) {
if ($_ % 2 == 0) {
push @even, $_;
}
}
Once you get used to the idea of functions accepting other functions
(or blocks) as parameters.
Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
.
- References:
- Curly braces and the logic of PERL
- From: Brian
- Re: Curly braces and the logic of PERL
- From: "Chas. Owens"
- Re: Curly braces and the logic of PERL
- From: Rob Dixon
- Curly braces and the logic of PERL
- Prev by Date: dbdimp.c:1: error:
- Next by Date: Re: Curly braces and the logic of PERL
- Previous by thread: Re: Curly braces and the logic of PERL
- Next by thread: Re: Curly braces and the logic of PERL
- Index(es):
Relevant Pages
|