Perl tips

– 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 :

#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 :


#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.

%d bloggers like this: