in reply to Matching double characters and insertion

Sometimes regex isn't the answer to all problems. I see a better solution using straightforward perl to get around the problem of how regex's work. (Mind you, there might be a regex solution, but here, I know this works ;-)
my @array = split //, $string; my @newarray; my $c = shift @array; while ( @array ) { my $d = shift @array; push @newarray, $c; if ( $c eq $d ) { push @newarray, 'x'; } $c = $d; } push @newarray, $c; $string = join '', @newarray; #update
----------------------------------------------------- Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: Matching double characters and insertion
by japhy (Canon) on Jul 20, 2001 at 06:05 UTC
    Only if you join() @newarray.

    _____________________________________________________
    Jeff japhy Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;