On Mon, Mar 31, 2008 at 2:30 PM, Rob Dixon <[EMAIL PROTECTED]> wrote:
snip
>  >     my $sepchar = ',';
>  >     for (@_) { $sepchar = ";" and last if /\Q$sepchar/ }
>
>  This relies on ';' being true, and uses 'and' in void context.
>
snip

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 ...
>
>  wouldn't work; or, rather, it would work but wouldn't exit from the loop
>  when intended.
snip

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.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to