Table of Contents

Variable Interpolation

We still haven't finished learning from that humble bit of code. To refresh your memory, here it is again:

$string="perl";
$num1=20;
$num2=10.75;
print "The string is $string, number 1 is $num1 and number 2 is $num2\n";

Notice the way the variables are used in the string. Sticking     variables inside of strings has a technical term - "variable     interpolation". Now, if we didn't have the handy $ prefix for we'd have to do something like     the example below, which is pseudocode. Pseudocode is code to demonstrate a    concept, not designed to be run. Like certain Microsoft software.   

print "The string is ".string." and the number is ".num."\n";

which is much more work. Convinced about those prefixes yet ?

Try running the following code:

$string="perl";
$num=20;
print "Doubles: The string is $string and the number is $num\n";
print 'Singles: The string is $string and the number is $num\n';
   

Double quotes allow the aforementioned variable interpolation. Single quotes do not. Both have their uses as you will see later, depending on whether you wish to interpolate anything.