develooper Front page | perl.perl5.porters | Postings from April 2006

Re: [PATCH] t/op/pat.t using

Thread Previous | Thread Next
Ronald J Kimball
April 27, 2006 07:52
Re: [PATCH] t/op/pat.t using
Message ID:
On Thu, Apr 27, 2006 at 04:06:35PM +0200, David Landgren wrote:
> Jim Cromie wrote:
> >does it matter that $1 is only set on a match (IIRC), and that an old value
> >could accidentally match the expected  ?  ('foo' being as common as it is)
> >I imagine the tests avoided that potential..
> You are quite right, they do, so some defensive coding would be required.
> perl -le '$_="ab";/(a)(b)/; print "X$1$2"; /(c)/; print "Y$1$2"'
> Xab
> Yab
> perl -le '$_="ab";/(a)(b)/; print "X$1$2"; undef=~/()/; /(c)/; print 
> "Y$1$2"'
> Xab
> Y
> Or through local
> perl -le '$_="ab";{local $1,$2;/(a)(b)/; print "X$1$2"} {local $1,$2; 
> /(c)/; print "Y$1$2"}'
> Xab
> Y

You don't need local; the curly braces are sufficient.

perl -le '{$_="ab";/(a)(b)/; print "X$1$2";} {/(c)/; print "Y$1$2"}'


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About