Perl Variables

Numbers – http://www.tizag.com/perlT/perlnumbers.php

Strings – http://www.tizag.com/perlT/perlstrings.php

Why type doesn’t matter

Strong vs. Weak Quotes

Using Variables

Variables with a single value: scalars

$scalar

Variables holding a list of values: arrays

@array

Creating and populating arrays:

@months = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);

$array[0] # for instance $months[0] = Jan

$#array # gives array length minus 1 (0 based)

$#array_name # the length of the array

Variables holding a list of keys and values: hashes:

%hash

Creating and populating hashes:

%months_days = (Jan => 31, Feb => 28, Mar => 31, Apr => 30, May => 31, Jun => 30, Jul => 31, Aug => 31, Sep => 30, Oct => 31, Nov => 30, Dec => 31);

$hash{0} # for instance $months_days{“Jan”} = 31 # Notice that you use a scalar marker when referring to a single value in the hash

print $months_days{“Sep”}; # This prints 30

Resources

Beginner’s Intro to Perl by Doug Sheppard: Variables

http://www.tizag.com/perlT/perlvariables.php

http://www.tizag.com/perlT/perlarrays.php