From: Rob Dixon <[EMAIL PROTECTED]>
> 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
===== [EMAIL PROTECTED] === 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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/