[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Re: all subsets



On May 15, Ton Hospel said:

>We also played with that idea that day. For "real" substrings I came up with:
>
>perl -wle 'sub p{pop=~/.+?(??{print$&})/};p("abc")'

Which breaks on strings with 1 in them.  And since the algorithm does ANY
sequence, not just connected sequences, you need to take the
capture-or-not-capture approach.

  use re 'eval';
  sub p{local$_=pop;/@{[map'(?:(.)|.)',1..length
        ]}(?{print+join'',map$$_,1..length})^/x}

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe