Next: String Scalar Variables
Up: Scalar Variables
Previous: Scalar Variables
You define scalar variables by assigning a value (number or string) to it.
- You do not declare variable types at a special place in the program
as in PASCAL.
- It is a good idea to declare all variables together near the top of
the program.
The following are simple examples (var1.pl) of variable
declarations:
$first_name = "David";
$last_name = "Marshall";
$number = 3;
$another_number = 1.25;
$sci_number = 7.25e25;
$octal_number = 0377; # same as 255 decimal
$hex_number = 0xff; # same as 255 decimal
NOTE:
- All references to scalar variables need a $.
- Perl commands end with a semicolon (;). This can be omitted from
last lines of ``blocks'' of statements like PASCAL.
- All standard number formats are supported integer, float and
scientific literal values are supported.
- Hexadecimal and Octal number formats are supported by 0x and 0
prefix.
dave@cs.cf.ac.uk