in reply to Positional regex statements
Here is one of my favorite tricks using substr's lvalue property.
The list of positions is reversed to make the substitutions work from right to left, so that the positions remain valid as the substitutions are made. That substitution and regex will non-destructively insert a comma in the given position even if there is no whitespace there, and will also eat leading whitespace from that position if it exists.for my $spot (reverse 11,25,31,35,39,44,49,66,71,76,78) { substr($_, $spot) =~ s/^\s*/,/; }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Positional regex statements
by jcoxen (Deacon) on Oct 05, 2004 at 14:05 UTC |