Perl Interview Questions and Answers PDF Download

Perl Interview Questions and Answers
Join TelegramJoin Telegram
Join Whatsapp GroupsJoin Whatsapp

Welcome to Perl interview questions and answers section. We have provided top 50 frequently asked Perl interview questions and answers. You can either prepare online from this article or prepare offline by downloading the provided Perl interview questions in PDF format provided by Freshersnow.com

You can also check: Perl Online Quiz

★★ You can also check: Latest Technical Interview Questions ★★

Table of Contents

Perl Interview Questions and Answers

1. What is perl language?

  • Perl stands for “Practical Extraction and Reporting Language”.
  • It is a programming language specially designed for text editing.
  • It’s a powerful scripting language and is rich in features.
  • By using Perl, we can also write powerful and efficient code that can be used in mission-critical projects.

2. What are the various flags/ arguments that can be used while executing a Perl program?

The following arguments can be used while executing a Perl program.

  • w – argument shows a warning.
  • d – used for debugging.
  • c – compiles only do not run.
  • e – execute
  • pl –wd filename.pl variables

3. Comment on data types and variables in Perl?

Perl variables do not have a data type. The data type of a variable in Perl is inferred from its value.
The variable in Perl can be defined as follows:

$x = 10;
$base_str = ‘Hello’;

The value needs to be assigned to a variable before using it. the program may result in an unexpected output.

4. What are the different string manipulation operators in Perl?

Perl provides two different operators to manipulate strings.

  • Concatenation operator (.): Combines two strings to form a result string.
  • Repetition operator (x): Repeats string for a specified number of times.

Example

$str1 = “abc”;
$str2 = “def”;
$str3 = $str1.$str2;#concatenates the string and str3 has value ‘abcdef’

5. Comment on array slicing and range operator?

Array slicing allows a user to retrieve more than one the elements of an array at once.

Example

@myarray=(1,2,3,4,5);
@subarray = @myarray[0,1];
Print (“@subarray\n”);

Output: 1 2
Thus ‘Slice’ the existing array and retrieve its elements.

We can also slice an array into large slices using “List-range operator” of Perl. While the List-range operator allows us to specify a range which will return all the elements in that range.

Example

@daysOfMonth = (1..31);#daysOfMonth will contain 1 to 31 elements.
@fortnight = @daysOfMonth[1..15];

This will assign a slice consisting of first 15 elements to a fortnight array.

6. What is “grep” function in Perl?

  • The grep function in Perl used for Pattern matching as in other scripting languages.
  • The “grep” function works on a list.
  • It evaluates an expression or a block for each element of the List.
  • For each statement that returns true as a result of evaluating an expression, it adds that element to the list of returning values.

Look at the following code snippet:

#!/usr/bin/perl@list =(“foo”,10,0,”bar”,20);
@has_string = grep( /\s/,@list );
Print “@has_string\n”;

Output: foo bar

This code executes “grep” command on a list and matches the pattern string (/s) to the list. The output is only the elements.

7. Create a function that is available only inside the scope where it is defined?

$pvt = Calculation(5,5);
print("Result = $pvt\n");
sub Calculation{my ($fstVar, $secndVar) = @_;
my $square = sub{return($_[0] ** 2);
};
return(&$square($fstVar) + &$square($secndVar));
};

Output: Result = 50

8. Can we load binary extension dynamically?

Yes, the binary extension can be load dynamically but your system supports that. In case if it doesn’t support, then you can statically compile the extension.

9. How to replace every TAB character in a file with a comma?

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

10. Write syntax to add two arrays together in Perl?

Syntax: @arrayvar = (@array1,@array2);

To accomplish the same, we can also use the push function.

11. How many types of operators are used in Perl?

  • Arithmetic operators: +,–,*
  • Assignment operators: += , -+, *=
  • Increment/ decrement operators: ++, – –
  • String concatenation: ‘.’ operator
  • comparison operators: ==, !=, >, < , >=
  • Logical operators: &&, ||, !

12. Explain what is Perl one-liner?

It is one command line programs and can be executed from the command line immediately.

Example

# run program under the debugger
perl-d my_file

13. List the data types of Perl?

There are different data types in Perl. They are as follows:

  • Scalars: It stores a single value.
  • Arrays: It stores a list of scalar values.
  • Hashes: It stores associative arrays.

14. Write syntax to use a grep function?

Syntax:

grep BLOCK LIST
grep (EXPR, LIST)

15. What is the use of -n and -p options?

This -n and -p options are used to wrap scripts inside loops. The -n option used to execute the Perl script inside the loop. The -p option also used the same loop as -n loop but in addition to it, it uses to continue. If both -n and -p options are used together with the -p the option is given the preference.

16. Mention what is CPAN?

CPAN means Comprehensive Perl Archive Network, a large collection of Perl software and documentation.

17. How can you say that Perl is compiler?

It was because the interpreter in the Perl is actually free to convert the program into the small codes.

18. Can the Compiled form be stored as a file in Perl?

No, it cannot be stored as a File

19. What is Closure in Perl and how it is helpful?

It was defined as the block of code in Perl which is used for capturing the lexical variable which can be accessed at a later section in a program.

20. Difference between Use and Require?

UseRequire
a method is used for modulesa method is used for both modules and libraries
objects are verified at compilation timeobjects are verified at run time

 21. What kind of data is supported by this programming language?

There are three types of data namely:

  • arrays of scalars
  • scalars
  • Hashes of scalars

22.Why to use Perl?

  • It is a powerful interpreter for free.
  • Perl is flexible and portable. It was very easy to learn Perl language.

23. Difference between C++ and Perl?

C++Perl
C++ objects data can be accessed outside its classPerl objects data cannot be accessed outside its class
C++ doesn’t support closuresPerl use closures with unreachable private data as objects
C++ does support pointer arithmeticPerl doesn’t have pointer arithmetic

 24. Name an Instance you used in Cpan module?

The common packages used from CPAN are CGI, DBI. there are thousands of other useful modules.

25. What is Hash in Perl?

Hash is basically used to comment the script line. This hash is an unordered set of key/value pairs that you access using strings as subscripts, to look up the scalar value corresponding to a given key.

26. What is the difference between Chop & Chomp functions in Perl?

chopchomp
chop is used to remove last characterchomp function removes only line endings

 27. How do you open a file for writing?

open FILEHANDLE, ">$FILENAME"

28. What Command used for Help in Perl?

perldoc -f print

29. What is the use Of “stderr()”?

It is a special filehandle for standard error in any package.

30. What is Super?

Super refers to current package ancestor.

31. What does Init 5 and Init 0 do?

  • init 5 will shutdown and Power-off the server.
  • init 0 will bring the server to the ok> prompt

32. What does Ndd do?

ndd command will hardcore the speed of the network interface card.

33. What is Obp and how do you access it?

OBP is called as Open Boot PROM. This OBP can be accessiable thru ok> prompt

34. How do you boot from Cd-rom?

Booting from CD-ROM can be done by the command

ok >boot cdrom

35. What is /etc/system for?

/etc/system is a kernal file of Solaris OS.

36. How do you boot from a network with Jumpstart?

boot net - install

37. What is it meants by ‘$_’?

It is a default variable which holds automatically, a list of arguments passed to the subroutine within parenthesis.

39. What is the Tk Module?

It provides a GUI interface.

38. How to Concatinate strings in Perl?

through.operator

40. How do find the Length of an Array?

$@array

41. What does Read() Return at end of file?

It was defined 0 value is the proper indication of the end of file for read() and sysread().

42. What is a Perl identifier?

A Perl identifier is a name used to identify a variable, function, class, module, or other objects. Perl variable name starts with either $, @ and also % followed by zero or more letters, underscores, and digits (0 to 9).

43. What package do you use to create windows services?

use Win32:: OLE.

44. How interpreter is used in Perl?

The interpreter compiles the Perl program internally into a parse tree. words after a profound symbol will be ignored. Once compiled, the interpreter will execute it immediately.

45. Explain the meaning of closure in Perl?

The closure is a block of code that is used to capture the environment where it is defined, and it captures lexical variables that the block consists of.

46. Is Perl a case sensitive language?

Yes, Perl is a case sensitive programming language.

47. What is the variable context in Perl?

Perl treats the same variable differently based on Context, the i.e. situation where a variable is being used.

48. What is the purpose of _FILE_ literal?

It is used to get the current file name.

49. What is the range operator?

The range operator (..) is used to create sequential arrays.

#!/usr/bin/perl
@var_10 = (1..10);
@var_20 = (10..20);
@var_abc = (a..z);
print "@var_10\n"; 
#Prints number from 1 to 10print "@var_20\n";#Prints number from 10 to 20print 
"@var_abc\n"; #Prints number from a to z

Here double dot (..) is called range operator. This will produce the following result −

1 2 3 4 5 6 7 8 9 10
10 11 12 13 14 15 16 17 18 19 20
a b c d e f g h i j k l m n o p q r s t u v w x y z

50. What is the purpose of strftime() function?

You can use the POSIX function strftime() to format date and time.

Download Perl Interview Questions and Answers in PDF Format: Click Here