Creating Variables in Perl

Perl variables do not have to be explicitly declared to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.

Keep a note that this is mandatory to declare a variable before we use it if we use strict statement in our program.

The operand to the left of the = operator is the name of the variable, and the operand to the right of the = operator is the value stored in the variable. For example −

$age = 25;              # An integer assignment
$name = "John Paul";    # A string
$salary = 1445.50;      # A floating point

Here 25, "John Paul" and 1445.50 are the values assigned to $age, $name, and $salary variables, respectively. Shortly we will see how we can assign values to arrays and hashes.

Updated on: 28-Nov-2019


Kickstart Your Career

Get certified by completing the course

Get Started