Perl Scalar Variables

Copy the text below and run it as a Perl script.

# scalar variables are prefixed by a $ sign;
# they can hold string literals and numbers

# ASSIGNING SCALAR VARIABLES

$myVar1 = "This is a string";
$myVar2 = 3.23;

print "1. ACCESSING SCALAR VARIABLES\n\n";

print $myVar1 . "\n";
print $myVar2 . "\n";

print "\n";


print "2. STRING INTERPOLATION\n\n";

# scalar variables can be interpolated into strings
# delimited by double quotation marks

for ($i = 1; $i < 4; ++$i)
{
   if ($i > 1) { $char = "s"; } 
  
   print "Let's do this $i time$char.\n";
}

print "\n";

# single quotation marks do not allow interpolation

$var = "world";

print 'Hello $var.';
print "\n";
print "\n";