Skip to content

Commit 9aead5b

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 29cc805 commit 9aead5b

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

pod/perlintro.pod

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,33 @@ 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 mean a dollar sign. Similarly
588+
C<.>, C<\>, C<[>, C<]>, C<(>, C<)>, and C<^> don't mean 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 have a meaning that isn't their literal value. There are a few
593+
more metacharacters than the ones above. Below some quantifier ones are
594+
given. (The full list is in L<perlre/Metacharacters>).
595+
596+
To make a metacharacter mean its literal value, you "escape" (or "quote")
597+
it, by preceding it with a backslash. C<\$> does mean a dollar sign,
598+
and C<\\> means a literal backslash.
599+
600+
Note also that above, the string C<\s>, for example, doesn't mean a
601+
backslash followed by the letter C<s>. In this case, preceding a
602+
non-metacharacter with a backslash turns it into something that doesn't
603+
mean its literal value. Such a sequence is called an "escape sequence".
604+
L<perlrebackslash> documents all of the current ones.
605+
606+
Perhaps paradoxically, escaping a metacharacter (by preceding it with a
607+
backslash) turns off it's normal meaning; while escaping a
608+
non-metacharacter creates an escape sequence that has a meta meaning.
609+
610+
You can specify how many of the previous thing you want to match on by
611+
using quantifiers (where "thing" means one of: a literal character, one
612+
of the constructs listed above, or a group of either of them in
613+
parentheses).
591614

592615
* zero or more of the previous thing
593616
+ one or more of the previous thing

0 commit comments

Comments
 (0)