Home » Perl Basics » 03 - Variables
3

Scalars

Scalar variable stores single value

A scalar is a type of variable that will store a single value. Single value does not equal single character. It can be a word, a number a group of word ..etc.. any one unique value. Example:
“1”, ”125”, “name”, “why do you do that?” are single values.

#!/usr/bin/Perl  -w
# author:
#modified by:
# date:
#Purpose: Hello World
$name = “marc”;
print  “$name”;
#END
In that simple script we created the scalar variable $name. All scalar variables use the following form:
  $name-of-the-variable = “value-of-the-variable”
The space before and after is not necessary in order for the script to run properly. It is however advised as it makes the reading of that script easier.
The name of the variable could be anything however it is a MUST to begin with a letter or an underscore “_”. The use of any other character as the first letter will return an error.
The text between the quotes will be interpreted. It means that you can if you want add n t etc to your variable as if they were in the main script. You can also use single quotes to have the value of the scalar not interpreted.