• +91 9723535972
  • info@interviewmaterial.com

Perl Interview Questions and Answers

Perl Interview Questions and Answers

Question - 51 : - Can we load binary extension dynamically?

Answer - 51 : -

Yes, we can load binary extension dynamically but your system supports that. If it doesn’t support, then you can statically compile the extension.

Question - 52 : - Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.

Answer - 52 : -

Syntax:

$result = $firststring . ” “.$secondstring;

Program:

#!/usr/bin/perl

$firststring = "abcd";

$secondstring = "efgh";

$combine = "$firststring $secondstring";

print "$Combine\n";
Output:

abcd efgh

Question - 53 : - How do I replace every TAB character in a file with a comma?

Answer - 53 : -

perl -pi.bak -e 's/\t/,/g' myfile.txt

Question - 54 : - In Perl, there are some arguments that are used frequently. What are that arguments and what do they mean?

Answer - 54 : -

-w (argument shows warning)

-d (use for debug)

-c (which compile only not run)

-e (which executes)

We can also use combination of these like:

-wd

Question - 55 : - How many types of primary data structures in Perl and what do they mean?

Answer - 55 : -

The scalar: It can hold one specific piece of information at a time (string, integer, or reference). It starts with dollar $ sign followed by the Perl identifier and Perl identifier can contain alphanumeric and underscores. It is not allowed to start with a digit. Arrays are simply a list of scalar variables.

Arrays:

Arrays begin with @ sign. Example of array:

my @arrayvar = ("string a", "string b "string c");
Associative arrays: It also frequently called hashes, are the third major data type in Perl after scalars and arrays. Hashes are named as such because they work very similarly to a common data structure that programmers use in other languages–hash tables. However, hashes in Perl are actually a direct language supported data type.

Question - 56 : - Which functions in Perl allows you to include a module file or a module and what is the difference between them?

Answer - 56 : -

“use”

The method is used only for the modules (only to include .pm type file)
The included objects are verified at the time of compilation.
We don’t need to specify the file extension.
loads the module at compile time.
“require”

The method is used for both libraries and modules.
The included objects are verified at the run time.
We need to specify the file Extension.
Loads at run-time.
suppose we have a module file as “Module.pm”

use Module;

or

require “Module.pm”;

(will do the same)

Question - 57 : - Which guidelines by Perl modules must be followed?

Answer - 57 : -

Below are guidelines and are not mandatory

The name of the package should always begin with a capital letter.

The entire file name should have the extension “.pm”.

In case no object oriented technique is used the package should be derived from the Exporter class.

Also if no object oriented techniques are used the module should export its functions and variables to the main namespace using the @EXPORT and @EXPOR_OK arrays (the use directive is used to load the modules).

Question - 58 : - How the interpreter is used in Perl?

Answer - 58 : -

Every Perl program must be passed through the Perl interpreter in order to execute. The first line in many Perl programs is something like:

#!/usr/bin/perl
The interpreter compiles the program internally into a parse tree. Any words, spaces, or marks after a pound symbol will be ignored by the program interpreter. After converting into parse tree, interpreter executes it immediately. Perl is commonly known as an interpreted language, is not strictly true. Since the interpreter actually does convert the program into byte code before executing it, it is sometimes called an interpreter/compiler. Although the compiled form is not stored as a file.

Question - 59 : - For a situation in programming, how can you determine that Perl is a suitable?

Answer - 59 : -

If you need faster execution the Perl will provide you that requirement. There a lot of flexibility in programming if you want to develop a web based application. We do not need to buy the license for Perl because it is free. We can use CPAN (Comprehensive Perl Archive Network), which is one of the largest repositories of free code in the world.

Question - 60 : - Write syntax to add two arrays together in perl?

Answer - 60 : -

@arrayvar = (@array1,@array2);
To accomplish the same, we can also use the push function.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners