Skip to content

Commit 0337b54

Browse files
committed
perlintro: Define metacharacter before using the term
This adds a bit of text about metacharacters that was missing from this introductory pod.
1 parent 064a75f commit 0337b54

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

pod/perlintro.pod

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,32 @@ the meantime, here's a quick cheat sheet:
584584
^ start of string
585585
$ end of string
586586

587-
Quantifiers can be used to specify how many of the previous thing you
588-
want to match on, where "thing" means either a literal character, one
589-
of the metacharacters listed above, or a group of characters or
590-
metacharacters in parentheses.
587+
Note that in the above, C<$> doesn't match a dollar sign. Similarly
588+
C<.>, C<\>, C<[>, C<]>, C<(>, C<)>, and C<^> don't match the characters
589+
you might expect. These are called "metacharacters". In contrast, the
590+
characters C<a>, C<e>, C<i>, C<o>, and C<u>, for example, are not
591+
metacharacters. They match themselves literally. Metacharacters
592+
normally match something that isn't their literal value. There are a few
593+
more metacharacters than the ones above. Some quantifier ones are
594+
given below, and the full list is in L<perlre/Metacharacters>.
595+
596+
To make a metacharacter match its literal value, you "escape" (or "quote")
597+
it, by preceding it with a backslash. Hence, C<\$> does match a dollar sign,
598+
and C<\\> matches a literal backslash.
599+
600+
Note also that above, the string C<\s>, for example, doesn't match a
601+
backslash followed by the letter C<s>. In this case, preceding the
602+
non-metacharacter C<s> with a backslash turns it into something that
603+
doesn't match its literal value. Such a sequence is called an "escape
604+
sequence". L<perlrebackslash> documents all of the current ones.
605+
606+
A warning is raised if you escape a character that isn't a metacharacter
607+
and isn't part of a currently defined escape sequence.
608+
609+
You can specify how many of the previous thing you want to match on by
610+
using quantifiers (where "thing" means one of: a literal character, one
611+
of the constructs listed above, or a group of either of them in
612+
parentheses).
591613

592614
* zero or more of the previous thing
593615
+ one or more of the previous thing

0 commit comments

Comments
 (0)