Perl Interview Questions and Answers

Perl Interview Questions and Answers

Perl Online Training in India

1)      Explain Perl ?

A)     PERL is Practical Extraction and Reporting language, which is a high level programming language written by Larry Wall. PERL is a free open source language. Generally PERL is used to develop web based applications even though libraries are available to program web server applications, database interfaces and networking components. Example: The popular e-commerce site was developed with PERL.

2)      How do you know the reference of a variable whether it is a reference, scaller, hash or array?

A) There is a ‘ref’ function that lets you know

3)      What is meant by a ‘pack’ in perl?

A) Pack converts a list into a binary representation. Takes an array or list of values and packs it into a binary structure, returning the string containing the structure. It takes a LIST of values and converts it into a string. The string contains a con-catenation of the converted values. Typically, each converted values looks like its machine level representation.

4)      How to implement stack in Perl?

A) Through push() and shift() function. Push adds the element at the last of array and shift() removes from the beginning of an array.

5)      What is Grep used for in Perl?

A) Grep is used with regular expression to check if a particular value exists in an array. It returns 0 it the value does not exists, 1 otherwise.

6)      What are scalar data and scalar variables?

A) Perl has a flexible concept of data types. Scalar means a single thing, like a number or string. So the Java concept of int, float, double and string equals to Perl\’s scalar in concept and the numbers and strings are exchangeable. Scalar variable is a Perl variable that is used to store scalar data. It uses a dollar sign $ and followed by one or more alphanumeric characters or underscores. It is case sensitive.

7)      How do you find the length of an array?

A)    $@array

8)      How many ways can we express string in Perl?

A)    Many. For example ‘this is a string’ can be expressed in:

“this is a string”

qq/this is a string like double-quoted string/

qq^this is a string like double-quoted string^

q/this is a string/

q&this is a string&

q(this is a string)

9)      What value is returned by a lone `return;’ statement?

A)    The undefined value in scalar context, and the empty list value () in list context. This way functions that wish to return failure can just use a simple return without worrying about the context in which they were called.

10)  How to concatenate strings with Perl?

A)    Method #1 – using Perl’s dot operator:

$name = ‘checkbook’;

$filename = “/tmp/” . $name . “.tmp”;

Method #2 – using Perl’s join function

$name = “checkbook”;

$filename = join “”, “/tmp/”, $name, “.tmp”;

Method #3 – usual way of concatenating strings

$filename = “/tmp/${name}.tmp”;

11)  What is Perl one-liner?

A)    There are two ways a Perl script can be run:

–from a command line, called one-liner, that means you type and execute immediately on the command line. You’ll need the -e option to start like “C:\ %gt perl -e “print \”Hello\”;”. One-liner doesn’t mean one Perl statement. One-liner may contain many statements in one line.

–from a script file, called Perl program.

12)  What happens when you return a reference to a private variable?

A)    Perl keeps track of your variables, whether dynamic or otherwise, and doesn’t free things before you’re done using them.

13)  How do you print out the next line from a filehandle with all its bytes reversed?

A)    Print scalar reverse scalar <FH>

Surprisingly enough, you have to put both the reverse and the <FH> into scalar context separately for this to work.

14)  How can we generate a list of all .html files in a directory?

A)    Here is a snippet of code that just prints a listing of every file in teh current directory. that ends with the entension #!/usr/bin/perl -w opendir(DIR, “.”); @files = grep(/\.html$/,readdir(DIR)); closedir(DIR); foreach $file (@files) { print “$file\n”; }

15)  What is the TK module?

A) It provides a GUI interface

For Best Perl Scripting Online Training in India please visit