2.4. VariablesNot surprisingly, there are three variable types corresponding to the three abstract data types we mentioned earlier. Each of these is prefixed by what we call a funny character.[5] Scalar variables are always named with an initial $, even when referring to a scalar that is part of an array or hash. It works a bit like the English word "the". Thus, we have:
Note that we can use the same name for $days, @days, and %days without Perl getting confused. There are other, fancier scalar terms, useful in specialized situations that we won't go into yet. They look like this:
Entire arrays (or slices of arrays and hashes) are named with the funny character @, which works much like the words "these" or "those":
Any of these constructs may also serve as an lvalue, specifying a location you could assign a value to. With arrays, hashes, and slices of arrays or hashes, the lvalue provides multiple locations to assign to, so you can assign multiple values to them all at once: @days = 1 .. 7; Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|