in reply to YET another regexp puzzle

Like this?
my $c = 0; $_ = "jigglewort\n"; print and $c++ while s/(.{$c})(.)(.)/$1$3$2/;
producing:
ijgglewort igjglewort iggjlewort iggljewort igglejwort igglewjort igglewojrt iggleworjt igglewortj

Replies are listed 'Best First'.
Re: Re: YET another regexp puzzle
by carric (Beadle) on Nov 20, 2003 at 02:33 UTC
    I didn't want to "move" the first char across the string. I want to swap 1&2, 2&3, 3&4. This way:

    12345
    21345
    13245
    12435
    12354

    Thanks though.. your idea is cool. EVERY response helps me learn a little more even if it's not exactly what I was after.