On Tue, 16 Jul 2002, Brent Dax wrote:

> I was reading through the Monastery, and I noticed a node (about the
> line between what's considered Perl discussion and what's off-topic)
> that had this regex in it:
> 
>       m:iw/how [do[es]?|can] [I|one] @tasks in @non_perl_languages/
> 
> (Yes, people are already using Perl 6 regexes in text.  :^) )  Reading
> this, I noticed a potential problem in :w.
> 
> To put it simply, what do these expand to?
> 
>       m:w/foo [~|bar]/
>       m:w/[~|bar] foo/
>       m:w/[~|bar] [^|baz]/
>       m:w/@foo @bar/

A5 says:

Another new modifier is :w, which causes an implicit match of whitespace 
wherever there's literal whitespace in a pattern. In other words, it 
replaces every sequence of actual whitespace in the pattern with a \s+ 
(between two identifiers) or a \s* (between anything else). 

So, since groups aren't identifiers, I imagine [the first] would expand 
to:

 m/ foo \s* [~ | bar] /

But I could see reason for this:

 m/ foo [\s* ~ | \s+ bar] /

But as your third and fourth case point out, this is not always easy to 
represent. Perhaps :w wouldn't transform the rexex, but keep "markers" on 
where there was whitespace in the regex. At each marker, If the last thing 
it matched was a \w, and it's currently trying to match a \w, match \s+ 
first, else match \s* first. This could have some problems that I'm not 
seeing...

But I do think the idea would make sense.

Luke

Reply via email to