in reply to Character positioning

Hi,

All these approches are fine, but one seems to forget that a word can contain the character multiple times. I would follow an entire new direction.

my $word="cacao"; my @word=split ('',$word); my @string=('_') x scalar @word; my $char="c"; map { $string[$_] = $char if $word[$_] eq $char } 0..$#word; print @string;
prints
c_c__

So, instead of working with strings, I would work with arrays. I even think this is faster than multiple substr lookups, but I am not sure.
---------------------------
Dr. Mark Ceulemans
Senior Consultant
IT Masters, Belgium