Piers Cawley wrote:
> Graham Barr <[EMAIL PROTECTED]> writes:
> > On Fri, Aug 11, 2000 at 01:47:12PM +0100, Piers Cawley wrote:
> > > >   /^_/
> > > >
> > > > What is that matching ?
> > >
> > > We've done this. It's matching a string that begins with '_'. Which is
> > > why, if you want to disambiguate you do /^{_}/ just like you do with
> > > variables.
> >
> > No that won't work either. That matches the string {_}
>
Damian and I put this example into the RFC explicitly. I like what I wrote
the first time, so I'll just repeat it:
----
=head2 Resolving ambiguity

The following is ambiguous:

        $check_start = $somestring =~ /^_foobar/;


This should be interpreted as an immediate pattern match for '_foobar' at
the start of a string. To cause this to be interpreted as a higher order
function, the ambiguity must be resolved through using braces:

        $check_start = $somestring =~ /^{_}foobar/;

which creates a higher order function testing for its argument, followed
by 'foobar', anywhere in $somestring. That is:

        $check_start = sub { $somestring =~ /$_[0]foobar/ };
----
It wouldn't be too hard to get P52P6 to recognise ^{something} in a regex
and quote it, would it? (And to make the quoting work properly...) I was
hoping that the use of {} would seem reasonably intuitive given the
similarity to their use in resolving ambiguity in dereferencing and
interpoling variables.


Reply via email to