Scalar variables are assigned scalar values with an assignment operator (the equals sign) in an assignment statement: $thousand = 1000; assigns the integer 1000, a scalar value, to the scalar variable $thousand . The assignment statement looks like an equal sign from elementary mathematics, but its meaning is different. The assignment statement is an instruction, not an assertion. It doesn't mean " $thousand equals 1000." It means "store the scalar value 1000 into the scalar variable $thousand ". However, after the statement, the value of the scalar variable $thousand is, indeed, equal to 1000. References are usually saved in scalar variables. For example: $pi = .14159265; If you try to print $pi after this assignment, you get an indication that it's a reference to a scalar value at a memory location represented in hexadecimal digits. To print the value of a variable that's a reference to a scalar, precede its name with an additional dollar sign: print $pi,"\n"; print $$pi, "\n"; This gives the output: SCALAR(0x811d1bc) 3.14159265 You can assign values to several scalar variables by surrounding variables and values in parentheses and separating them by commas, thus making lists: ($one, $two, $three) = ( 1, 2, 3); There are several assignment operators besides = that are shorthand for longer expressions. For instance, $a += $b is equivalent to $a = $a + $b . Table A-1 is a complete list. Table A-1. Assignment operator shorthands
|