in reply to regexp, substitution and the "pipe symbol"
There's no point in first doing a match, and then a substitution. If it doesn't match, the substitution won't happen, and if it match, the substitution happens as well. Furthermore, because your match includes a |, that pipe symbol will be in $1, and it will be unescaped. But you interpolate $1 in your substitution, so there the pipe symbol will be seen as an alternation.while ($string =~ /(\s+\|)/) { $string =~ s/$1/\|/; }
What you want is:
No while necessary.$string =~ s/\s+\|/|/g;
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: regexp, substitution and the "pipe symbol"
by jockel (Beadle) on Jan 30, 2004 at 13:51 UTC |