in reply to Replace only selected characters
Yet another way using a global look-ahead match and pos to find the commas then substr to erase all but the first, working back from the end of the string.
knoppix@Microknoppix:~$ perl -E ' > $l = q{abc,def,ghi,jkl,mno}; > say $l; > push @p, pos $l while $l =~ m{(?=,)}g; > substr $l, $_, 1, q{} for reverse @p[ 1 .. $#p ]; > say $l;' abc,def,ghi,jkl,mno abc,defghijklmno knoppix@Microknoppix:~$
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Replace only selected characters
by hbm (Hermit) on Oct 17, 2011 at 13:37 UTC | |
by rohanan (Novice) on Oct 17, 2011 at 16:23 UTC |