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

Re: [FWP] string increment



Rick Delaney wrote:

> And now for something completely different.
> 
>   perl -le'print$_=aaaa;for$i(1..4){print++$_ for($_)x25;$\=chop.$\}'

wow that is a beautiful hack, using $\ to include the old zees.
    perl -le'print@A=(a)x4;map{for$c(b..z){$A[$_]=$c;print@A}}3,2,1,0'
still has you by one stroke :)

    perl -le'$_=aaaa;do{print}while(s/([^z])(z*)\Z/++($a=$1).$2/e)'

Oh, you already found that one  -- your regexp is better than
mine, it has no \Z (a $ would be shorter) -- but mine only has one print

    perl -le'$_=aaaa;do{print}while s/(.*)([^z])/$1.++($x=$2)/e'

Or, using $' -- which requires doublequoting -- or calling it $POSTMATCH
which essentially knocks the ball into the lake

    perl -le'$_=aaaa;do{print}while(/[a-y]+/and$_=++($x=$&).$'"'"')'

    perl -le'$_=aaaa;while(print,/[a-y]+/){$_=++($x=$&).$'"'"}

    perl -le'$_=aaaa;$_=++($x=$&).$'"' while print,/[^z]+/"

Looks like I've reinvented s///    

    perl -le'$_=aaaa;1while print,s/[^z]+/++($x=$&)/e'

I do not understand the point behind having $\d and $& and so forth
treated
like constants.  The memory is reserved for them somewhere, I want to be
able
to modify it.  I guess I can't because taint checking would be too big a
performance hit, and writing to them is rarely called for and is easily
worked around.  Or is it because they are pointers directly into the
matched
string, instead of copies?

How much guts modification would be required to do selective
incrementing
with s/whatever/++$&/e ?  Is this on the long to-do list?  Or is it
inadvisable?  (expecting to be told that there was a big discussion of
this exact issue  during a boaf at perlcon 2 or something)

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