@@ -17,7 +17,8 @@ values indexed by their associated string key.
17
17
18
18
Values are usually referred to by name, or through a named reference.
19
19
The first character of the name tells you to what sort of data
20
- structure it refers. The rest of the name tells you the particular
20
+ structure it refers. This character is called a "sigil". The rest of
21
+ the name tells you the particular
21
22
value to which it refers. Usually this name is a single I<identifier>,
22
23
that is, a string beginning with a letter or underscore, and
23
24
containing letters, underscores, and digits. In some cases, it may
@@ -28,8 +29,9 @@ to locate the namespace in which to look up the final identifier
28
29
on identifiers, see L</Identifier parsing>. It's possible to
29
30
substitute for a simple identifier, an expression that produces a reference
30
31
to the value at runtime. This is described in more detail below
31
- and in L<perlref>.
32
- X<identifier>
32
+ and in L<perlref>. It is legal, but not recommended, to separate a
33
+ variable's sigil from its name by space and/or tab characters.
34
+ X<identifier> X<sigil>
33
35
34
36
Perl also has its own built-in variables whose names don't follow
35
37
these rules. They have strange names so they don't accidentally
@@ -41,7 +43,7 @@ the inner working of Perl have names containing punctuation characters.
41
43
These are documented in L<perlvar>.
42
44
X<variable, built-in>
43
45
44
- Scalar values are always named with '$', even when referring to a
46
+ Scalar values are always named with the sigil '$', even when referring to a
45
47
scalar that is part of an array or a hash. The '$' symbol works
46
48
semantically like the English word "the" in that it indicates a
47
49
single value is expected.
@@ -52,21 +54,21 @@ X<scalar>
52
54
$days{'Feb'} # the 'Feb' value from hash %days
53
55
$#days # the last index of array @days
54
56
55
- Entire arrays (and slices of arrays and hashes) are denoted by '@',
56
- which works much as the word "these" or "those" does in English,
57
+ Entire arrays (and slices of arrays and hashes) are denoted by the sigil
58
+ '@', which works much as the word "these" or "those" does in English,
57
59
in that it indicates multiple values are expected.
58
60
X<array>
59
61
60
62
@days # ($days[0], $days[1],... $days[n])
61
63
@days[3,4,5] # same as ($days[3],$days[4],$days[5])
62
64
@days{'a','c'} # same as ($days{'a'},$days{'c'})
63
65
64
- Entire hashes are denoted by '%':
66
+ Entire hashes are denoted by the sigil '%':
65
67
X<hash>
66
68
67
69
%days # (key1, val1, key2, val2 ...)
68
70
69
- In addition, subroutines are named with an initial '&', though this
71
+ In addition, subroutines are named with an initial sigil '&', though this
70
72
is optional when unambiguous, just as the word "do" is often redundant
71
73
in English. Symbol table entries can be named with an initial '*',
72
74
but you don't really care about that yet (if ever :-).
@@ -81,8 +83,9 @@ is a part of @foo, not a part of $foo. This may seem a bit weird,
81
83
but that's okay, because it is weird.
82
84
X<namespace>
83
85
84
- Because variable references always start with '$', '@', or '%', the
85
- "reserved" words aren't in fact reserved with respect to variable
86
+ Because variable references always start with the sigils '$', '@', or
87
+ '%', the "reserved" words aren't in fact reserved with respect to
88
+ variable
86
89
names. They I<are> reserved with respect to labels and filehandles,
87
90
however, which don't have an initial special character. You can't
88
91
have a filehandle named "log", for instance. Hint: you could say
0 commit comments