Re: commify_series script in cookbook page 94
- From: chas.owens@xxxxxxxxx (Chas. Owens)
- Date: Mon, 31 Mar 2008 15:44:39 -0400
On Mon, Mar 31, 2008 at 2:30 PM, Rob Dixon <rob.dixon@xxxxxxx> wrote:
snip
> my $sepchar = ',';snip
> for (@_) { $sepchar = ";" and last if /\Q$sepchar/ }
This relies on ';' being true, and uses 'and' in void context.
There is nothing wrong with using and in void context. If you have a
problem with it then you have a problem with many Perl idioms such as
open my $fh, "<", $file
or die "could not open $file: $!";
This uses or in void context. The use of and and or to control flow
is a long standing feature of the language. Perhaps you are confusing
the use of grep and map in a void context being bad. They are bad in
a void context because they are inefficient compared to the equivalent
for loops in some versions of Perl (prior to 5.8.1) and they have no
benefits in comparison with the for loop (it isn't shorter or more
clear).
snip
$sepchar = '' and last if ...snip
wouldn't work; or, rather, it would work but wouldn't exit from the loop
when intended.
Look at the intent of the piece of code again. Having an empty string
for a separator would be meaningless (and would break the regex). A
better example would be "0", but even that is pushing it since zero is
not a traditional separator character.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
.
- References:
- Interpolate variable in a __DATA__ block
- From: Trudge
- Re: Interpolate variable in a __DATA__ block
- From: Gunnar Hjalmarsson
- Re: Interpolate variable in a __DATA__ block
- From: Trudge
- Re: Interpolate variable in a __DATA__ block
- From: Chas. Owens
- commify_series script in cookbook page 94
- From: Richard Lee
- Re: commify_series script in cookbook page 94
- From: Dr.Ruud
- Re: commify_series script in cookbook page 94
- From: Richard Lee
- Re: commify_series script in cookbook page 94
- From: Rob Dixon
- Re: commify_series script in cookbook page 94
- From: Dr.Ruud
- Re: commify_series script in cookbook page 94
- From: Rob Dixon
- Interpolate variable in a __DATA__ block
- Prev by Date: Re: Uninitialized value in pattern match
- Next by Date: Re: commify_series script in cookbook page 94
- Previous by thread: Re: commify_series script in cookbook page 94
- Next by thread: Re: commify_series script in cookbook page 94
- Index(es):
Relevant Pages
|