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