Think of a scalar as an empty box. You label it, and you store a single piece of data in it. That data might be a number, a letter, a paragraph, or an entire web page - it could be anything, but only a single thing. Perl is a 'loosely typed' language, meaning that you don't need to explicitly state what kind of data you're putting into your variables. Perl will automatically handle the gory details of type to the best of its ability.
A scalar is designated by placing a $ in front of a variable name ('variable' because the contents of the box can be changed) you've chosen for your empty box. This name could be anything, provided it contains only letters, or the underscore character. You may also use numbers, but you may not begin a variable name with a number. It is generally a good idea to name your variables in such a way that you can easily identify what they're for, or at least in what context they're being used. For example:
$theTotal
$counter
$feature_image_1
These are all fairly simple and clear. These, however, are ugly and invalid variable names:
$num!
$44%over
$1234
To place data inside your variable 'box' you must use an operator, specifically the assignment operator (an equal sign):
$theTotal = 1;
$my_name = 'Bobby';
Let's take a look at an extremely simple program to see this in action.
#!/usr/local/bin/perl
$my_name = 'Bobby';
print $my_name;
You should see output similar to the following:
$ ./simpleProgram.pl
Bobby$
Notice that your prompt is stuck on the same line as the word 'Bobby'? In Perl, the newline character is represented with a '\n', so we could fix this little graphical glitch with a simple modification to our print statement:
print "$my_name\n";
Now your output will be on its own line above your fresh prompt. But why did we add the quotes?
