Perl Interview Questions

Perl Questions Important for Interview:

This article enlists the most important Perl Interview Questions/topics that we generally need in our Perl based programming or in the interviews based on Perl .

Perl Interview Questions :

perl interview questions
Perl interview questions

  1. Get all the Perl module installed via ubuntu/Linux command line ?

perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'File::Find and File::Spec::Functions module are used to list all installed modules.
  • -M option loads the module. It executes use module before executing the script
  • -T option enables taint checking, which instructs Perl to keep track of data from the user and avoid doing anything insecure with it. Here this option is used to avoid taking the current directory name from the @INC variable and listing the available .pm files from the directory recursively.
  • -l option enables automatic line-ending processing in the output. Print statements will have the new line separator (\n) added at the end of each line.
  • -w option prints any warning messages.
  • -e option indicates that the following string is to be interpreted as a Perl script (i.e., sequence of commands).

Simple way to do it :

>find / -name \*.pm -type f
to know the pakage related to INC :

find `perl -e ‘map {print “$_ “} @INC’` -name \*.pm -type f

2. View Perl Documentation From Unix Command Line ?

You can use either perldoc or man command to get help about a particular Perl module as shown below:
$ perldoc Regexp::Common


$ man Regexp::Common
If the Perl document is not enough, use perldoc option -m,  to view both source code and unformulated pod documentation of the specified Perl module.

3. Verify Perl Module Is installed or not?

Syntax: Perl -M”Module name” 
if it gives no Output i.e indicates that the module is installed, else it shows an error stating the module not installed.

4. what is flip-flop Operator in Perl?

The flip-flop operator is useful for skipping the first iteration when looping through the records (usually lines) returned by a filehandle, without using a flag variable:
  next if 1..1; # skip first record

 [bibblio style=”bib–row-3 bib–default bib–hover bib–white-label bib–font-arial bib–size-18″ query_string_params=e30=]

5.Perl Interview Questions: what is a null filehandle diamond operator?

The null filehandle diamond operator <> has its place in building command-line tools. It acts like <FH>to read from a handle, except that it magically selects whichever is found first: command-line filenames or STDIN. Taken from perlop:

while (<>) {
...   # code for each line

 6. What is Map ?

The map built-in function is one of the most useful tools in your toolkit. map takes a list and applies a code block to every element, returning the list. You can think of it as stream processing: you push the list in one side and get it back on the other side with some transformation applied. Inside the code block, you refer to the current element with the traditional "$_" variable.
Example below demonstrate the function for perl code using map to conver the Uppercase .
my @l = qw(perl php python);
my @uc_l = map { uc($_) } @l;
7.  what is ||= operator ?
In Perl, you can use the ||= operator. Its precedence rules are such that it’ll only do an assignment if the value is false (‘false’ generally means zero, undefined, or the empty string):
$a ||= 5;
Other Article: Android compatibility with Ubuntu

Also Click to  Read : SSH without password   and  Mysql Connection Error

Leave a Reply

Your email address will not be published. Required fields are marked *