Re: commify_series script in cookbook page 94



Richard Lee wrote:
Dr.Ruud wrote:
Richard Lee schreef:


While reading perl cookbook, I came to page 94 and having a hard time
understanding this particular phrase

my $sepchar = grep( /,/ => @_ ) ? ";" : ",";

Shortcutting alternative:

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

but (unless @_ is quite big) the grep alternative is likely to be
faster.


I understood the original but I am not so sure of your solution??

Can you write it out completely so that I can try it out?

It's equivalent to:

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

And IMO is much better written that way.

HTH,

Rob
.



Relevant Pages

  • Re: Speed limit at C a misconception?
    ... > My understanding of the phrase "nothing can go faster than light" ... then the phrase "nothing can go faster than light ... information, energy, momentum, and angular momentum "material objects". ...
    (sci.optics)
  • Re: Shortage of sperm donors
    ... Nobby, you mean? ... But he's away with the camels again, ... Is there a clear understanding of what, exactly, this phrase means? ...
    (uk.media.radio.archers)
  • Re: Reactions to/against the Binary Tree
    ... one would have to conclude that this person is nuts. ... This is utter nonsense with the common understanding of the phrase "every ... understanding will he have about infinite sets, ...
    (sci.logic)
  • Re: Fortran is the word an acronym or a portmanteau?
    ... using initial letters from words in a phrase. ... My understanding has always been that it is RAdio Detection And Ranging. ...
    (comp.lang.fortran)
  • Re: how much is a circumcision?
    ... not understanding things, so that's fine. ... It's the phrase that distinguishes whether one is someone who practices ... Judaism.. ...
    (uk.rec.motorcycles)