On Wed, Jan 27, 2010 at 08:40:48AM -0800, Larry Wall wrote:
> On Wed, Jan 27, 2010 at 01:24:48PM +0000, Matthew Walton wrote:
> : On Wed, Jan 27, 2010 at 1:19 PM, Carl Mäsak <cma...@gmail.com> wrote:
> : > Mark (>), Carl (>>):
> : >>> S05 describes tr/// in terms of the .trans function, a handsome but
> : >>> very different beast. Specifically, it doesn't seem to have a "scalar
> : >>> context", with which one could count things.
> : >>
> : >> What does trans return in numeric (+) context?
> : >
> : > As spec'd, it returns the numification of the string resulting from
> : > the substitution, I guess.
> : >
> : > // Carl
> : >
> : 
> : $str.comb(/C|G/).join('').chars might do it. It's maybe not quite as 
> elegant...
> 
> Hmm, what might be more elegant?  Maybe something like...
> 
>     [+] $str.comb.Bag<C G>;
> 
> Probably does too much work building the Bag though, unless it can be
> lazy somehow.  But the point is that Bags are really just histograms
> with a cute name.

That or the optimiser is capable of recognising the entire construction, and
compiling it down to something efficient.

For example, how

   @a = sort @a;
   foreach (reverse @a) { ... }
   ... reverse sort { ... } ...
   if (%hash) { ... }

now work in Perl 5, by being optimised to a more efficient execution sequence.

Nicholas Clark

Reply via email to