Home Interview Questions and Answers Perl Interview Questions and Answers For Graduates Part-2

perl11,What is variable context in perl?
Perl treats same variable differently based on Context, i.e. situation where a variable is being used.

12.What is scalar context?
Assignment to a scalar variable evaluates the right-hand side in a scalar context.

13.What is a list context?
Assignment to an array or a hash evaluates the right-hand side in a list context.

14.What is boolean context?
Boolean context is simply any place where an expression is being evaluated to see whether it’s true or false.

15.What is void context?
This context not only doesn’t care what the return value is, it doesn’t even want a return value.

16.What is interpolative context?
This context only happens inside quotes, or things that work like quotes.

17.What is the difference between single quoted string and double quoted string?
Single quoted string prints the perl variable as a string whereas double quoted string evaluates the variable and used to get the variable’s value.


$var = “This is string scalar!”;
$quote = ‘I m inside single quote – $var’;
$double = “This is inside double quote – $var”;

$escape = “This example of escape -\tHello, World!”;

print “var = $var\n”;
print “quote = $quote\n”;
print “double = $double\n”;
print “escape = $escape\n”;
This will produce the following result −

var = This is string scalar!
quote = I m inside single quote – $var
double = This is inside double quote – This is string scalar!
escape = This example of escape – Hello, World!

18.What is V-Strings?
A literal of the form v1.20.300.4000 is parsed as a string composed of characters with the specified ordinals. This form is known as v-strings.

A v-string provides an alternative and more readable way to construct strings, rather than use the somewhat less readable interpolation form “\x{1}\x{14}\x{12c}\x{fa0}”.

19.What is the purpose of _FILE_ literal?
It is used to get the current file name.

20.What is the purpose of _LINE_ literal?
It is used to get the current line number.

You may also like

Leave a Comment