diff options
author | Charles Bailey <bailey@HMIVAX.HUMGEN.UPENN.EDU> | 1997-03-10 18:08:08 -0500 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-03-09 11:57:19 +1200 |
commit | a54cb1465fdb400848f23705a6f130bb5c34ab70 (patch) | |
tree | 2926f6f65210a5eaae06abb91d3f8a399845a3d7 | |
parent | 63a6ff3a1dc8d86edb4d8a7ec1548205e32a7114 (diff) | |
download | perl-a54cb1465fdb400848f23705a6f130bb5c34ab70.tar.gz |
Document trap with //o and closures
Subject: Re: Possible bug: /o overeager in closure constructor
Chip Salzenberg <chip@atlantic.net> 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<all> 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
-rw-r--r-- | pod/perltrap.pod | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/pod/perltrap.pod b/pod/perltrap.pod index 17c576df2f..c31d299284 100644 --- a/pod/perltrap.pod +++ b/pod/perltrap.pod @@ -1127,6 +1127,23 @@ found using the C<pos()> function--see L<perlfunc/pos>). 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<all> 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 |