Re: commify_series script in cookbook page 94



Rob Dixon wrote:
Dr.Ruud wrote:
Rob Dixon schreef:
It's equivalent to:

my $sepchar = ',';
foreach (@_) {
if (/,/) {
$sepchar = ';';
last;
}
}

And IMO is much better written that way.
TIMTOWTDI.

But I'm sure you'll agree that some ways are more awkward or obfuscated
than others.

Another shortcutting alternative:

my $sepchar = ',';
for (@_) { $sepchar = ";" and last if /\Q$sepchar/ }

This relies on ';' being true, and uses 'and' in void context.

"'and' in void context"? 'and' has two operands so how is it in void context?



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.