next up previous contents index
Next: Double Quoting Up: Variables Previous: Variables   Contents   Index


Scalar Variables

In Perl, simple (scalar) variables have names beginning with a `$' sign, followed by a varable name. The name Thus, $number is a valid name, as is $NumBer123, but $2number or $number-max are not. Note that variable names are case sensitive, so that $name and $NAME are independent variables.

A very good practice to get into the habit of is to choose variable names which are descriptive of the quantity they represent. This will help enormously when others (or you) examine your program. In this regard, the use of the underscore character can help in the readability - $maximum_score is easier to read than $maximumscore.

Assignment of a value to a variable is done through the `=' sign:

  $city = "Winnipeg";
  $score = 33;
Note that numbers, either integer or floating point, are not quoted, but strings must be. Also note that large numbers cannot contain a comma - $salary = 1,000,000 isn't valid. As a shorthand for large or small numbers you can either use scientific notation ($salary = 1e6), or use the special Perl syntax $salary = 1_000_000.

There are two main methods of quoting.


Subsections
next up previous contents index
Next: Double Quoting Up: Variables Previous: Variables   Contents   Index