From: Charles Bailey Date: Mon, 10 Mar 1997 23:08:08 +0000 (-0500) Subject: Document trap with //o and closures X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a54cb1465fdb400848f23705a6f130bb5c34ab70;p=p5sagit%2Fp5-mst-13.2.git Document trap with //o and closures Subject: Re: Possible bug: /o overeager in closure constructor Chip Salzenberg wrote: | | According to Charles Bailey: | > OK, so eval "" is the current workaround (but not eval '', if some of | > the lexicals come from a block scope :-)). Should this be documented? | | IMO, it deserves an entry in perltrap. How 'bout something like =item * Regular Expression Currently, if you use the /o qualifier on a regular expression within an anonymous subroutine, I closures generated from that anonymous sub constructor will use the regular expression compiled the very first time the constructor was called. For instance, if you say sub build_match { my($left,$right) = @_; return sub { $_[0] =~ /$left stuff $right/o; }; } build_match will always return a sub which matches the contents of C<$left> and <$right> from the first time it was called, not from the current call. This is probably a bug, and may change in future versions of Perl. It's a bit long, but I can't think of a more concise explanation that's not confusing. BTW, should we have a perlbugs.pod or somesuch as a home for things like this, which aren't so much stable changes in the language as problems we haven't been able to sort out yet? p5p-msgid: 01IGCHWRNSEU00661G@hmivax.humgen.upenn.edu --- diff --git a/pod/perltrap.pod b/pod/perltrap.pod index 17c576d..c31d299 100644 --- a/pod/perltrap.pod +++ b/pod/perltrap.pod @@ -1127,6 +1127,23 @@ found using the C function--see L). You may always reset the iterator yourself as shown in the commented line to get the old behavior. +=item * Regular Expression + +Currently, if you use the /o qualifier on a regular expression within +an anonymous subroutine, I closures generated from that anonymous +sub constructor will use the regular expression compiled the very +first time the constructor was called. For instance, if you say + + sub build_match { + my($left,$right) = @_; + return sub { $_[0] =~ /$left stuff $right/o; }; + } + +build_match will always return a sub which matches the contents of +C<$left> and <$right> from the first time it was called, not from +the current call. This is probably a bug, and may change in future +versions of Perl. + =back =head2 Subroutine, Signal, Sorting Traps