Re: commify_series script in cookbook page 94



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

And I also don't understand what ";" is doing in the ternary operator??
The ";" is what is returned if the condition is TRUE.

"( / ,/ => @_)" is a(n anonymous) hash. I've had no idea that grep can
operate on a hash.
However, it seems that "grep( / ,/ => @_)" and "grep( / ,/, @_)" are equivalent.
__CODE__
@a = qw/aa ab ba bb/;
print join(", ", grep(/a/, @a) );
print "\n";
print join(", ", grep(/a/ => @a) );
print "\n";
__END__
aa, ab, ba
aa, ab, ba

@_ is a list/array, and that is what grep is searching for the RegEx / ,/.
@_ is the arguments passed into the current function/sub.
In this context, grep is being used in a scalar context. So it returns
the number of times that "the expression is true", ie the number of
elements that contain a " ,". In a TRUE/FALSE context, it returns
whether any of the passed arguments have a " ,". If there is a " ," in
one of the arguments, the $sepchar is set to ";". Otherwise it is set
to ",".

HTH!
.



Relevant Pages

  • Re: PAQ compression
    ... >> next 12 bits hold a hash value computed from previous bytes. ... In early versions of PAQ the context ... numeric data, not so much for "ordinary" data, eg, text). ... A group of 4 elements forms a bucket. ...
    (comp.compression)
  • Re: Forcing list context
    ... > scalar context so grep returns the number of matches instead of the ... > I intended to go on to do a list splice to get the fields I wanted ...
    (comp.lang.perl.misc)
  • Text Parser Help Please
    ... a context and starts with the @ symbol. ... hash key for the task. ... I gues the best way might be to extract each marker assin it to a hash ...
    (comp.lang.ruby)
  • Re: Text Parser Help Please
    ... a context and starts with the @ symbol. ... breaking them down by white space into an array and then using a regex ... hash key for the task. ... I gues the best way might be to extract each marker assin it to a hash ...
    (comp.lang.ruby)
  • Re: "made hash out of" [was: Re: Way too good to pass up....]
    ... Your point is that in British English "make a hash of" ... or will suss it out in context. ... But in American English "make hash of" means to chop up, ...
    (alt.usage.english)