Perl Interview Questions and Answers
Question - 71 : - List the prefix dereferencer in Perl.
Answer - 71 : -
$-Scalar variables
%-Hash variables
@-arrays
&-subroutines
Type globs-*myvar stands for @myvar, %myvar.
Question - 72 : - What are the advantages of c over Perl?
Answer - 72 : -
There are more development tools for C than for PERL. PERL execute slower than C programs. Perl appears to be an interpreted language but the code is complied on the fly. If you don’t want others to use your Perl code you need to hide your code somehow unlike in C. Without additional tools it is impossible to create an executable of a Perl program.
Question - 73 : - “Perl regular expressions match the longest string possible”. What is the name of this match?
Answer - 73 : -
It is called as “greedy match” because Perl regular expressions normally match the longest string possible.
Question - 74 : - How can you call a subroutine and identify a subroutine?
Answer - 74 : -
‘&myvariable’ is used to call a sub-routine and ‘&’ is used to identify a sub-routine.
Question - 75 : - What is use of ‘->’ symbol?
Answer - 75 : -
In Perl, ‘->’ symbol is an infix dereference operator. if the right hand side is an array subscript, hash key or a subroutine, then the left hand side must be a reference.
@array = qw/ abcde/; # array
print "n",$array->[0]; # it is wrong
print "n",$array[0]; #it is correct , @array is an array
Question - 76 : - Where do we require ‘chomp’ and what does it mean?
Answer - 76 : -
We can eliminate the new line character by using ‘chomp’. It can used in many different scenarios.For example:
excuteScript.pl FstArgu.
$argu = $ARGV[0];
chomp $argu; --> to get rid of the carrige return.
Question - 77 : - What does the’$_’ symbol mea
Answer - 77 : -
n?
The ‘$_’ is a default variable in Perl and $_ is known as the “default input and pattern matching space
Question - 78 : - What is the syntax used in Perl grep function?
Answer - 78 : -
The syntax used in Perl is
- grep BlOCK LIST
- grep ( EXPR, LIST )
- BLOCK: It contains one or more statements delimited by braces, the last statement determines in the block whether the block will be evaluated true or false.
- EXPR: It represents any expression that supports $, particularly a regular expression. Against each element of the list, expression is applied, and if the result of the evaluation is true, the current element will be attached to the returned list
- LIST: It is a list of elements or an array
Question - 79 : - Explain what are prefix dereferencer and list them out?
Answer - 79 : -
Using a particular prefix when you dereference a variable, they are called prefix dereferencer.
- $- Scalar variables
- %-Hash variables
- @-Arrays
- &-Subroutines
- Type globs-myvar stands for @myvar, %myvar
Question - 80 : - Explain what is the function of Return Value?
Answer - 80 : -
The Return Value function returns a reference to an object blessed into CLASSNAME.