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?

I don't see any problems with changing /1 to $1 in that regex.  It gives
the same results either way when I try it.  Of course, it fails
completely if there is whitespace in the middle of the string.

What I always do to strip leading and trailing whitespace is this:

s/^\s+|\s+$//g

-- 
Bowie

Reply via email to