Perlaccess : Tutorials : Variables
Scalar Variables (3.1)
by Jacob A. Wheeler
http://www.bigresources.com

One important part of any programming language is variables. Variables give you the ability to create dynamic applications, and store temporary information. Unlike some languages, in PERL you do-not have to declare the variables before you use them. Below are a few examples of how scalar variables can be used.

  1. $bob = "bob"; #Declare bob as bob
  2. $jerry = "jerry"; #Declare jerry as Jerry
  3. $bob = $jerry; #Bob now equals Jerry

Here is some example code on howto append scalar variables.

  1. $name = "John";
  2. $last = "Doe";
  3. $firstlast = $name . $last;
  4. $firstlast = "First: " . $name . " Last: " . $last;

The following will do the same thing.

  1. $name = "John";
  2. $last = "Doe";
  3. $firstlast = "First: " . $name;
  4. $firstlast .= " Last: " . $last;

Ready to move onto Arrays?