Karsten Bräckelmann wrote: > On Thu, 2010-06-10 at 12:08 +0200, Per Jessen wrote: >> > > I have a bit of SA code where I strip leading and trailing >> > > whitespace >> > > >> > > foreach (@addrs) { s/^\s*([^\s]+)\s*$/\1/; } >> > > >> > > Whenever I run this I get the warning "\1 better written as $1" >> > > which I understand to be perl telling me that the right side of >> > > s/// should >> > > use $digit, not \digit. I tried changing it to $1, but that >> > > didn't >> > > produce the expected result. What would be the correct way to >> > > write this? > >> There are no spaces in the string, it's an email address. > > So you don't actually want to strip leading and trailing whitespace, > but any whitespace. Makes it way easier and faster. :) Like > > tr/ //d;
Thanks! >> I did try using $1 on the right side of the s///, but it didn't work. > > The infamous "doesn't work" description... How so? What does it do? > What about injecting some dbg() lines before and after the > substitution? Well, as the \1 variation worked apart from the warning, I didn't bother with going any further. I have a feeling the $1 might be getting substituted first? so maybe I should escape it? Anyway, thanks for your suggestion, it's much better. /Per Jessen, Zürich