On Thu, 2005-05-12 at 13:44, Patrick R. Michaud wrote:
> On Thu, May 12, 2005 at 12:53:46PM -0400, Aaron Sherman wrote:
> > > In other words, it acts as though one had written
> > >
> > > $rule = rx :w / plane ::: (\d+) | train ::: (\w+) | auto ::: (\S+) / ;
> > >
> > > and not
> > >
> > > $rule = rx :w /[ plane :: (\d+) | train :: (\w+) | auto :: (\S+) ]/ ;
> >
> > Your two examples fail in the same way because of the fact that the
> > group IS the whole rule.
>
> False. In the first case the group is the whole rule. In the second
> case the group would not include the (implied) '.*?' at the start of
> the rule.
That cannot be true. If it were, then:
s/[a]//
and
s/a//
would replace different things, and they MUST NOT. If I've missed some
fundamental way in which rx:p5/(?:...)/ is different from rx/[...]/,
then please let me know. Otherwise, we can simply demonstrate this with
P5:
perl -le '"abcaabbcc" =~ /(?:aa)/;print $&'
and unshockingly, that prints "aa", not "abcaa"
> Note that the rule is *unanchored*, thus it tries at the first character,
> if it fails then it goes to the second character, if that fails it goes
> to the third, etc.
Yes, you're correct, but when you step forward over input in order to
find a start for your unanchored expression, you do NOT consume that
input, grouping or not. To say:
$foo ~~ /unanchored/
is something like
for 0..length($foo)-1 -> $i {
substr($foo,$i) ~~ /^unanchored/;
}
and always has been. Unless I'm unaware of some subtlety of [], it is
just the same as P5's (?:...), which behaves exactly this way.
I'll skip the rest of your post for now, except for the last bit, since
I think we need to resolve which universe we're in before we can give
each other street directions ;-)
> > > /[:w\bfoo bar]/ # not exactly the same as above
> >
> > No, I think that's exactly the same.
>
> Nope. Consider:
>
> $foo = rx /[:w::foo bar]/
> $baz = rx /[:w\bfoo bar]/
>
> "myfoo bar" ~~ $foo # matches
> "myfoo bar" ~~ $baz # fails, foo is not on a word boundary
You're correct, sorry about that.
--
Aaron Sherman <[EMAIL PROTECTED]>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback