Perl Programming Interview Questions You'll Most Likely Be Asked

Price: $19.95


Perl Programming Interview Questions You'll Most Likely Be Asked is a perfect companion to stand ahead above the rest in today’s competitive job market. Rather than going through comprehensive, textbook-sized reference guides, this book includes only the information required immediately for job search to build an IT career. This book puts the interviewee in the driver's seat and helps them steer their way to impress the interviewer.



Table of Contents
1. Basic Programming
2. Network Programming
3. Database Programming
4. Web Programming
5. Perl 6
6. Object Oriented Programming
7. File Processing
8. HR Questions



a) 200 Perl Programming Interview Questions, Answers and Proven Strategies for getting hired as an IT professional

b) Dozens of examples to respond to interview questions

c) 51 HR Questions with Answers and Proven strategies to give specific, impressive, answers that help nail the interviews

d) 2 Aptitude Tests download available on



Sample from the book
(Below Questions and Answers are randomly taken from different pages of the book)

11: What is the difference between chop() and chomp()?


chomp() and chop() are used to remove some characters from a scalar string. Normally a line is terminated by a newline character. $/ is a special variable known as Input Record Separator, which stores the character(normally ‘n’) which separates each record in a file. Chomp removes all the trailing characters which is stored in ‘$/’ variable (input record separator). Normally, chomp is used to remove the new line characters from the end of the string.

Chop would remove the last character from a string variable. If an array is given as the argument to chop() function, it would chop each element present in the list.


12: What is the output of the following code snippet?


my $num = 12;

print "The value of num = $numn";

print 'The value of num = $num';


The value of num = 12

The value of num = $num


There is a difference between double quotes (“”) and single quotes (‘’) in Perl. All the special strings placed between the double quotes will be resolved by the interpreter. This is called Interpolation. In the first statement, interpreter considered the $num as a scalar and replaced its value while printing.

In the second case, the string was printed as such without giving any special treatment to the string.


13: What is the difference between the two code snippets?

1. #!/usr/bin/perl

2. my $x = 67;

3. print "Value of x = $xn";

4. my $x = 77;

5. print "Value of x = $xn";


1. #!/usr/bin/perl

2. Use strict;

3. my $x = 67;

4. print "Value of x = $xn";

5. my $x = 77;

6. print "Value of x = $xn";


Output of first code:

Value of x = 67

Value of x = 77

Second code would result in error, due to Line# 2. If ‘use strict’ is used in a Perl script, interpreter would make it mandatory that every variable should be declared prior to using it and no variable can be re-declared. Since ‘use strict’ is not included in first code, it does not throw any error.


81: What is the output of the following code?

1. @arr1 = ("a","b","c");

2. @arr2 = ("d","e","f");

3. unshift @arr1,@arr2;

4. $, = "|";

5. print @arr1;


unshift will add the elements from arr1 to arr2. $ represents the output field separator. So line# 4 is assigning the output field separator as ‘|’.

Output: d|e|f|a|b|c


89: What is the output of the following statement?

print "desk" lt "desktop" ? "true" : "false";


Output: true

lt is less than operator which compares 2 strings. In Perl, when 2 strings are compared the ASCII value is compared. Since “desktop” is longer that “desk”, Perl will compute “desktop” as greater than “desk”.


127: How do you create a socket in client side?


use IO::Socket;

$sock = new IO::Socket::INET (PeerAddr => 'servicename',

PeerPort => 1200,

Proto => 'tcp',


die "Socket could not be created. Reason: $!n" unless $sock;


128: How do you implement a service which can read messages from a client and print it?


use IO::Socket;

$sock = new IO::Socket::INET (LocalHost => 'ChatService',   #service hostname

LocalPort => 1200,   #service port

Proto => 'tcp',   #protocol

Listen => 1,   #number of clients allowed

Reuse => 1


die "Socket could not be created. Reason: $!" unless $sock;

while ($connection = $sock->accept()) {   #accept client connection

while (defined ($message = <$connection>)) {   #read message from client

print $message;



close ($sock);   #close the socket



171: How do you find out from which package, subroutine, filename a code is being called?


We can use the caller method to find out the caller details.

sub func1()


($package, $file, $subroutine) = (caller(1))[0,1,3];

Print “Caller Package: $packagen”;

Print “Caller Filename: $filen”;

Print “Caller Subroutine: $subroutinen”;



172: What is bless operator?


bless operator is used to associate an object with a class.

package BlessClass;

my $obj = { };

bless $obj, "BlessClass";


This helps Perl to know which package to be searched, when a method is invoked using the object.


199: How do you give data to another program from a Perl program?



$pid = open(WRITE,"program args |")  or die "Couldn't fork: $!n";

print WRITE “arguments to the program;   #Give the arguments to the program

close(WRITE);   #Close the program


200: How do you print all the files from a directory using globbing?



@files = <*>;

foreach (@files)


print $_ . "n";



201: How do you rename all the .C files to .CPP in the current directory?



@Cfiles = <*.C>;

foreach (@Cfiles)


$cppfile = $_ . “PP”;

rename($_, $cppfile) or warn “Could not rename $_”;