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

Re: [FWP] string increment



On Tue, 25 Apr 2000, David L. Nicol wrote:

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

I don't know why I didn't see this earlier.  I guess I had to write a
dozen variations of every snippet that got posted and see the same outpout
over and over and over again before realizing that there was a pattern in
there:

    perl -le'/^a*.z*$/&&print for aaaa..zzzz'

> How much guts modification would be required to do selective
> incrementing with s/whatever/++$&/e ?  Is this on the long to-do list?

I've also wanted to modify $1, $2, etc.  Basically lie about what just got
matched.  For example, assigning to $1 instead of $match in the following:

    sub acronym {
        uc join '', map {substr $_, 0, 1} split ' ', shift;
    }

    my $re = qr/
        (.*)                        # Match entire string
        (?{$match = acronym($1)})   # Pretend we matched an acronym
    /x;

    print $match if "Just another Perl hacker" =~ /$re/;  # JAPH

-- 
Neko


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