Oct 13, 2021

PERL Interview Questions for VLSI Jobs : Part 2


1. What is interpolation in PERL ?

Double-quoted strings are “interpolated” : any variable names found inside the string will be replaced by their value. 

Example : 

2. Why we use strict module ?
Or
Why  “use strict” is a Must while using PERL Data Structures ?

Here is our PERL Code :


When we execute the code we get the below error message due to use of the STRICT Module :
Execution of ./accident.pl aborted due to compilation errors.
As a Corrective Action , Change  the print command to : print $aref->[2][2]

Global symbol "@aref" requires explicit package name (did you forget to declare "my @aref"?) at ./accident.pl line 9.


3. Tell/Show the  Difference between Chop and Chomp :

The chomp() function removes ONLY new line character from the end of the string. 
WHEREAS
The Perl chop() function removes last character from a string regardless of what that character is. 
Let us see the example below :


Produces the below output :

=======Mary Had a Little Lamb=============
=======Mary Had a Little Lamb=============
=======Mary Had a Little Lamb =============
=======Mary Had a Little Lamb=============
=======Mary Had a Little Lamb Once=============
=======Mary Had a Little Lamb Onc=============

Now you can spot the difference ..... or else watch the video well below this page.


4. Tell/Show The Difference between Concat & Join  :

  • Concat & Join both are used to stitch more than one strings together.
  • Concat is used in very straight forward & its a binary operator.
  • Join is a PERL function to join contents of a list/array.

Here goes our example to show the difference:

The output is :

 Happy Birthday
 Happy Morning 

Now you can spot the difference ..... or else watch the video well below this page.


5. How to local-ise a variable ?

This below example will help you to do that :

Which gives the output :

 Num=100 @ outside 
 Num=10 A
 Num=10 Quick
 Num=10 Brown
 Num=10 Fox

Watch the video well below this page for explanation.


6. How to read a file directly in to an array ?

Our input file contains : 
A quick 
Brown fox
Jumped Over
A Lazy
White Dog


Which we are reading through the below PERL Code:


Which gives output of the file being read:

$VAR1 = [
          'A quick ',
          'Brown fox',
          'Jumped Over',
          'A Lazy',
          'White Dog'
        ];



For detailed explanation of all above QnA, please watch this video :








Courtesy : www.pngegg.com