ewww.. isn't $& one of those variables that you should
almost never use (along with $' and $`) because it slows
down every pattern match afer that?
Actually I was refering to the s in your suggestion: s/./g wont even compile.
m/./g or equivalently /./g will
work with $& as you suggested. s/.// will
also work (note the lack of the g modifier), though it destroyes the original string.
I'm guessing you meant /./g which is why I
think it was a typo.
-Blake | [reply] [d/l] [select] |
The problem with "never use" had to do with some mode that would cause the string to be copied, and if it was used anywhere in the program it would stay on. But, that's been addressed with newer versions, and you copy it by using $1 anyway, so it's no worse. Try benchmarking it to see if saving the capture but capturing the whole match comes out ahead or behind or no change. I kind of figured that saving the capture was going to come out ahead.
Yes, I meant s, not m.
—John
| [reply] |