Perl Tips (part 1)

Posted on the 31 October 2011 by Skiabox @skiabox

- Variable Interpolation

This is a classic between many programming languages.

When we use a double quoted string, for every variable that we put inside the string , we get variable's value as part of the output when we execute our script.

For example :

 #!/usr/bin/perl
#script1 use 5.012;
my $name = "Stavros";
print "My name is $name\n";

script1 output -> My name is Stavros

On the other hand , interpolation doesn't happen with single-quoted strings, for example :

 #!/usr/bin/perl
#script2 use 5.012;
my $name = "Nick";
print 'My name is $name\n';

script2 output -> My name is $name\n

Here both the variable name and the newline character are printed in the screen, so they are not interpolated by Perl.