Perl Basics

The Print command, Double and Single Quotes

When used with the Print command Single and Double quotes behave differently.
Double quotes allow variable substitution whereas Single quotes do not.
For example, enter the following and execute it

$age = 30; 
$first_name = 'Lance';
$last_name = 'Boyle'; 
print "$first_name $last_name is $age \n";
print '$first_name $last_name is $age \n';

The output is

Lance Boyle is 30
$first_name $last_name is $age \n

Exercise
Enter the following program and run it

$vi='joe';
print '$vi is short for vile',"$vi is short for joes own editor";

Using Scalar (simple) Variables
As you have seen simple variables are identified in perl with a $ sign

You can "auto-increment" a scalar variable using the "++" operator:

Exercise
Enter the following program and execute it

            $number = 1;
            print "$number\n";
            $number++; 
            print "$number\n";

Perl should send the following to standard output

1
2

You can also perform arithmetic such as:

$value = $item_price * $quantity;
$shipping_price = 9.99 * $quantity;
$grand_total = $value + $shipping_price;