On 5/10/05, Aaron Crane <[EMAIL PROTECTED]> wrote:
> Damian Conway writes:
> > Just as $42 is a shorthand for $/[42], so too $<whatever> is a
> > shorthand for $/<whatever>.
> 
> Isn't $42 a shorthand for $/[41] ?
> 
> I think that having 1-based digit-variables but 0-based array indexes on
> $/ is really confusing; mistakes of this sort seem to confirm my view.

Yeah, I'm pretty sure they should be consolidated somehow.  Of course
we could make $# zero-based.  But there are other possibilities:

    * $/[0] is like $&, the full text of the match
    * $/[0] is the name of the matching rule, like in P::RD

The latter isn't applicable everywhere, but I have to say that it was
pretty handy.  But I'm not sure I ever used its zeroth position to my
advantage, so it would probably be better of a method on $/.

The former case is actually quite elegant if we extend it to the new
matching semantics.  Consider:

    "foobarbaz" ~~ / (foo (bar)) (baz) /

Then:

    $/[0] eq "foobarbaz";
    $/[1] is a match object
    $/[1][0] eq "foobar"
    $/[1][1][0] eq "bar"
    $/[2][0] eq "baz"

So now we have the strigification behavior on $/: it just returns its
zeroth element.  The current meaning of $0 is now consistent and means
exactly the same thing it used to.

But I'm in the middle of a movie, so I haven't really thought through
the rest of it clearly.  I think it breaks down somewhat in the
presence of quantifiers.

Luk

Reply via email to