Perl Scripting Interview Questions & Answers

1) What is Perl?
Ans: Perl stands for Practical Extraction and Reporting Language. It is a high-level programming language written by Larry Wall, specially designed for processing text. It supports object-oriented programming, and its syntax is quite similar to C language. It is much more flexible to use. Due to its strong text processing abilities, it has become one of the most popular languages for writing CGI scripts.

2) Is Perl Compiler or Interpreter?
Ans: Perl is said to be both compiler and interpreter. It reads the source code, converts the program into bytecode before execution and then runs it. Hence, Perl is sometimes called an interpreter/compiler.

3) Which operator in Perl is used for the concatenation of two strings?
Ans: The operator used for the concatenation of strings is (.) operator.

4) What is CPAN in Perl?
Ans: CPAN stands for Comprehensive Perl Archive Network. It is a repository which contains thousands of Perl modules.

5) What are the features of Perl language?
Ans: The feature of Perl:

It has a very simple Object-oriented programming syntax.
It is easily extendible as it supports 25,000 open source modules.
It supports Unicode.
Includes powerful tools to process text to make it compatible with markup languages like HTML, XML.
It supports third-party database including Oracle, MySQL, and many others.
It is embeddable in other systems such as web servers and database servers.
It is open source software licensed under GNU.
Many frameworks are written in Perl.
It can handle encrypted web data including e-commerce transactions.
It is a cross-platform language.
It offers a regular expression engine which can transform any text.
For more information: click here.

6) What are the advantages and disadvantages of Perl language?

Perl advantages:

Its syntax is simple, which makes it easy to understand.
It supports OOP concepts.
Perl programs run easily on the system.
It is more flexible to use.
It supports all platforms and is much more portable.
It has a rich set of Perl modules and free software.
It is much more efficient to work on text and string manipulation as it is a scripting language.
Perl combines features of many other languages which make it easy to understand.

Perl disadvantages

A Perl program containing CPAN modules will not run on another system which doesn’t have CPAN modules installed.
It is an interpretative language, so it is slower in comparison with other languages.
It has untidy and unreadable codes.
It starts creating problems when the code is larger than 200 lines.
It is not portable.

7) Define print() function in Perl?
Ans: The Perl print() function prints anything it gets as its argument.

8) Define say() function in Perl?
Ans: The Perl say() function is not supported by older Perl versions. It is like Perl print() function with only one difference that it automatically adds a new line at the end.

9) Define dynamic scoping.
Ans: The assignment of temporary values to the global variables is called as dynamic scoping.

10) Explain lexical variables.
Ans: The variables which are created by the use of ‘my’ operator and private in nature are called as lexical variables.

11) When does circular reference occur?
Ans: When the two references also contain references to each other, then the case of circular reference occurs.

12) What happens in dereferencing?
Ans: Value to the location from the reference point is returned.

13) What does read () command do?
Ans: The read() command is used to read the block of information from the buffered file handle.

14) What is the use of ‘ne’ operator?
Ans: The operator compares the value of the left string to the right one and returns true if they are not equal.

15) What does the q{ } operator do?
Ans: The operator encloses a string in the single quotes.

16) What does the qq{ } operator do?
Ans: The operator encloses a string in the double quotes.

17) What does the qx{ } operator do?
Ans: The operator encloses a string in the inverted quotes.

18) How many data types are there in Perl?
Ans: Perl has three data types:


19) What are Perl variables?
Ans: A variable is a place to store values reserving some memory space. Perl treats the same variables differently based on context.

There are three types of Perl variables:


20) What are scalars?
Ans: A scalar contains a single unit of data. They are preceded with a ($) sign. A scalar contains a number, character, reference or a string. A reference is the address of the variable.

21) What are arrays in Perl?
Ans: An array contains an ordered list of scalar values. It is preceded with (@) sign. To access a single element in a Perl array ($) sign is used.

22) How to find the length of an array in Perl?
Ans: Size of an array is determined with scalar context on the array. Array length will always be one greater than its largest index.

Perl size = $#arrayName +

Where $#arrayName is the maximum index of the array.

23) What are Perl array functions?
Ans: Perl array functions are used to add or remove some elements in an array.

There are four types Perl array functions:


24) What is Perl push array function?
Ans: The Perl push array function appends a new element at the end of an array.

25) What is Perl pop array function?
Ans: The Perl pop array function removes the last element of an array.

26) What is Perl shift array function?
Ans: The Perl shift array function removes the leftmost element from the array shortening array by 1.

27) What is Perl unshift array function?
Ans: The Perl shift array function adds a new element at the start of an array.

28) How to replace Perl array elements?
Ans: The Perl splice array function removes elements and replaces them with the specified list of elements.

29) How to convert strings into an array in Perl?
Ans: The Perl split array function splits a string into an array of strings. Thus converting strings into an array.

30) How to convert arrays into a string in Perl?
Ans: The Perl join array function combines more than one array into a single string. Thus converting arrays into a string.

For more  Click Here

For Course Content  Click Here