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;


> 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?


-- 
char *t="\10pse\0r\0dtu...@ghno\x4e\xc8\x79\xf4\xab\x51\x8a\x10\xf4\xf4\xc4";
main(){ char h,m=h=*t++,*x=t+2*h,c,i,l=*x,s=0; for (i=0;i<l;i++){ i%8? c<<=1:
(c=*++x); c&128 && (s+=h); if (!(h>>=1)||!t[s+h]){ putchar(t[s]);h=m;s=0; }}}

Reply via email to