Perl has three built-in data types: scalars, arrays of scalars, and
associative arrays of scalars, known as "hashes". Normal arrays
-are ordered lists indexed by number, starting with 0 and with
+are ordered lists of scalars indexed by number, starting with 0 and with
negative subscripts counting from the end. Hashes are unordered
-collections of values indexed by their associated string key.
+collections of scalar values indexed by their associated string key.
Values are usually referred to by name, or through a named reference.
The first character of the name tells you to what sort of data
reference-counting and destructor invocation.
A scalar value is interpreted as TRUE in the Boolean sense if it is not
-the empty string or the number 0 (or its string equivalent, "0"). The
+the null string or the number 0 (or its string equivalent, "0"). The
Boolean context is just a special kind of scalar context where no
conversion to a string or a number is ever performed.
You can also gain some miniscule measure of efficiency by pre-extending
an array that is going to get big. You can also extend an array
by assigning to an element that is off the end of the array. You
-can truncate an array down to nothing by assigning the empty list
+can truncate an array down to nothing by assigning the null list
() to it. The following are equivalent:
@whatever = ();
String literals are usually delimited by either single or double
quotes. They work much like quotes in the standard Unix shells:
double-quoted string literals are subject to backslash and variable
-substitution; single-quoted strings are not (except for "C<\'>" and
-"C<\\>"). The usual C-style backslash rules apply for making
+substitution; single-quoted strings are not (except for C<\'> and
+C<\\>). The usual C-style backslash rules apply for making
characters such as newline, tab, etc., as well as some more exotic
forms. See L<perlop/"Quote and Quotelike Operators"> for a list.
represent the current filename, line number, and package name at that
point in your program. They may be used only as separate tokens; they
will not be interpolated into strings. If there is no current package
-(due to an empty C<package;> directive), __PACKAGE__ is the undefined value.
-
-The tokens __END__ and __DATA__ may be used to indicate the logical
-end of the script before the actual end of file. Any following
-text is ignored, but may be read via a DATA filehandle: main::DATA
-for __END__, or PACKNAME::DATA (where PACKNAME is the current
-package) for __DATA__. The two control characters ^D and ^Z are
-synonyms for __END__ in the main program, __DATA__ in a separate
-module. See L<SelfLoader> for more description of __DATA__, and
+(due to an empty C<package;> directive), __PACKAGE__ is the undefined
+value.
+
+The two control characters ^D and ^Z, and the tokens __END__ and __DATA__
+may be used to indicate the logical end of the script before the actual
+end of file. Any following text is ignored.
+
+Text after __DATA__ but may be read via the filehandle C<PACKNAME::DATA>,
+where C<PACKNAME> is the package that was current when the __DATA__
+token was encountered. The filehandle is left open pointing to the
+contents after __DATA__. It is the program's responsibility to
+C<close DATA> when it is done reading from it. For compatibility with
+older scripts written before __DATA__ was introduced, __END__ behaves
+like __DATA__ in the toplevel script (but not in files loaded with
+C<require> or C<do>) and leaves the remaining contents of the
+file accessible via C<main::DATA>.
+
+See L<SelfLoader> for more description of __DATA__, and
an example of its use. Note that you cannot read from the DATA
filehandle in a BEGIN block: the BEGIN block is executed as soon
as it is seen (during compilation), at which point the corresponding
called in list context, followed by the key/value pairs of %glarch.
To make a list reference that does I<NOT> interpolate, see L<perlref>.
-The empty list is represented by (). Interpolating it in a list
+The null list is represented by (). Interpolating it in a list
has no effect. Thus ((),(),()) is equivalent to (). Similarly,
interpolating an array with no elements is the same as if no
array had been interpolated at that point.
$x = (($foo,$bar) = f()); # set $x to f()'s return count
This is handy when you want to do a list assignment in a Boolean
-context, because most list functions return a empty list when finished,
+context, because most list functions return a null list when finished,
which when assigned produces a 0, which is interpreted as FALSE.
The final element may be an array or a hash:
that function produces a new list which is a copy of the values,
so changing them doesn't change the original.
-As a special rule, if a slice would produce a list consisting entirely
-of undefined values, the empty list is produced instead. This makes
-it easy to write loops that terminate when an empty list is returned:
+A slice of an empty list is still an empty list. Thus:
+
+ @a = ()[1,0]; # @a has no elements
+ @b = (@a)[0,1]; # @b has no elements
+ @b = (1,undef)[1,0,1]; # @b has three elements
+
+This makes it easy to write loops that terminate when a null list
+is returned:
while ( ($home, $user) = (getpwent)[7,0]) {
printf "%-8s %s\n", $user, $home;
As noted earlier in this document, the scalar sense of list assignment
is the number of elements on the right-hand side of the assignment.
-The empty list contains no elements, so when the password file is
+The null list contains no elements, so when the password file is
exhausted, the result is 0, not 2.
If you're confused about why you use an '@' there on a hash slice