Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Matching a literal # in a rule

0 views
Skip to first unread message

Brad Bowman

unread,
Dec 2, 2005, 3:26:12 PM12/2/05
to perl6-l...@perl.org
Hello,

How can you match a literal "#" in a rule?
\# or only \x{23}?

S05 seems clear "# now always introduces a comment",
and \# is not listed in the escapes.

But then Perl 5 has \# so I assume it's just an omission...

Brad

--
A person who knows but a little will put on and air of knowledge. This
is a matter of inexperience. When someone know something well, it will
not be seen in his manner. This person is genteel. -- Hagakure

Patrick R. Michaud

unread,
Dec 2, 2005, 3:47:22 PM12/2/05
to Brad Bowman, perl6-l...@perl.org
On Fri, Dec 02, 2005 at 09:26:12PM +0100, Brad Bowman wrote:
> How can you match a literal "#" in a rule?
> \# or only \x{23}?
>
> S05 seems clear "# now always introduces a comment",
> and \# is not listed in the escapes.
>
> But then Perl 5 has \# so I assume it's just an omission...

Short answer: \# matches a literal '#'. (So does <'#'>.)

Longer answer: I think "always" may be too strongly worded
in S05, it's not meant as an absolute but rather it's contrasting
perl 6 expressions from perl 5 ones (as part of the "because /x
is default" above).

For example, a few lines earlier S05 says that "^ and $ now
always match the start/end of a string", but the "always" here
is mean to distinguish perl 6 from perl 5, where ^ and $ could
have different meanings depending on the /m option. Similarly,
in perl 5 a '#' could have different meanings depending on the /x
option, but in perl 6 it is always a metacharacter and introduces
a comment. To get a literal # you can escape it with a backslash.

Pm

0 new messages