1. What does the ‘strict’ pragma do in Perl?
a. Enables the use of uninitialized variables
b. Forces variables to be localized before use
c. Requires variables to be declared before use
d. Disables the use of regular expressions
Answer: c
2. What is the difference between ‘my’ and ‘local’ in Perl?
a. ‘my’ creates a global variable, while ‘local’ creates a local variable
b. ‘my’ creates a lexical variable, while ‘local’ creates a global variable
c. ‘my’ creates a private variable, while ‘local’ creates a shared variable
d. ‘my’ creates a static variable, while ‘local’ creates a dynamic variable
Answer: b
3. Which of the following is not a valid Perl data type?
a. Scalar
b. Array
c. Object
d. Hash
Answer: c
4. What is the Perl equivalent of ‘if-else’ statement in other programming languages?
a. unless
b. when
c. elseif
d. else
Answer: d
5. What is Perl’s default hash sorting method?
a. Numerically
b. Alphabetically
c. Randomly
d. There is no default sorting method
Answer: b
6. What is the purpose of the ‘use strict’ pragma in Perl?
a. To disable strict typing
b. To enable strict mode
c. To enable unsafe features
d. To allow undeclared variables
Answer: b
7. Which function is used to read input from the standard input in Perl?
a. input()
b. read()
c. get()
d. <>
Answer: d
8. What is the difference between ‘eq’ and ‘==’ in Perl?
a. ‘eq’ is used for string comparison, while ‘==’ is used for numerical comparison
b. ‘eq’ is used for numerical comparison, while ‘==’ is used for string comparison
c. Both are used for string comparison
d. Both are used for numerical comparison
Answer: a
9. What does the ‘chomp’ function do in Perl?
a. Removes whitespace at the beginning and end of a string
b. Removes a character from the end of a string
c. Removes a character from the beginning of a string
d. Removes a newline character from the end of a string
Answer: d
10. What is the difference between ‘open’ and ‘close’ functions in Perl?
a. ‘open’ is used to open a file, while ‘close’ is used to close a database connection
b. ‘open’ is used to create a new file, while ‘close’ is used to delete a file
c. ‘open’ is used to read from a file, while ‘close’ is used to write to a file
d. ‘open’ is used to open a file, while ‘close’ is used to close a file
Answer: d
11. What is the difference between ‘next’ and ‘last’ statements in Perl?
a. ‘next’ moves to the next iteration of a loop, while ‘last’ exits the loop
b. ‘next’ exits the loop, while ‘last’ moves to the next iteration of a loop
c. Both are used to exit the loop
d. Both are used to move to the next iteration of a loop
Answer: a
12. What is the Perl equivalent of a switch statement in other programming languages?
a. when
b. switch
c. case
d. if-elsif chain
Answer: d
13. What is a Perl reference?
a. A pointer to a memory location
b. A scalar value that refers to an array, hash or subroutine
c. A value that refers to a file handle
d. A reference to a Perl module
Answer: b
14. How do you declare a Perl subroutine?
a. function subroutine_name { }
b. sub subroutine_name { }
c. def subroutine_name { }
d. proc subroutine_name { }
Answer: b
15. Which symbol is used to dereference a Perl reference?
a. .
b. ->
c. ::
d. #
Answer: b
16. What does the expression ‘2 x 3’ evaluate to in Perl?
a. 5
b. 6
c. 8
d. 23
Answer: b
17. What is the difference between ‘+=’, ‘-=’, ‘=’, ‘/=’ and ‘%=’ in Perl?
a. They are all arithmetic operators
b. They are all assignment operators
c. ‘+=’ adds and assigns the value, ‘-=’ subtracts and assigns the value, ‘=’ multiplies and assigns the value, ‘/=’ divides and assigns the value, ‘%=’ modulo and assigns the value
d. ‘+=’ subtracts and assigns the value, ‘-=’ adds and assigns the value, ‘*=’ divides and assigns the value, ‘/=’ multiplies and assigns the value, ‘%=’ adds and assigns the value
Answer: c
18. What does the ‘split’ function do in Perl?
a. Splits a string into an array of substrings
b. Splits an array into a string
c. Joins two arrays into a single array
d. Joins two strings into a single string
Answer: a
19. Which function is used to get the length of a string in Perl?
a. length()
b. str_length()
c. len()
d. count()
Answer: a
20. What is the Perl equivalent of a for-in loop in other programming languages?
a. for (my $i=0; $i<=10; $i++) { }
b. foreach my $item (@array) { }
c. for my $key (keys %hash) { }
d. for (my $i=10; $i>=0; $i–) { }
Answer: b
21. Which of the following is not a Perl regular expression metacharacter?
a. *
b. +
c. $
d. ?
Answer: c
22. What is the difference between ‘reverse’ and ‘sort’ functions in Perl?
a. ‘reverse’ reverses the order of elements in an array, while ‘sort’ sorts the elements in ascending order
b. ‘reverse’ sorts the elements in descending order, while ‘sort’ reverses the order of elements in an array
c. ‘reverse’ reverses the order of elements in an array, while ‘sort’ sorts the elements in descending order
d. ‘reverse’ sorts the elements in ascending order, while ‘sort’ reverses the order of elements in an array
Answer: c
23. What is the difference between ‘print’ and ‘printf’ functions in Perl?
a. ‘print’ displays output on the screen, while ‘printf’ writes output to a file
b. ‘print’ displays output on the screen, while ‘printf’ formats output and then displays it on the screen
c. ‘print’ writes output to a file, while ‘printf’ displays output on the screen
d. ‘print’ formats output and then displays it on the screen, while ‘printf’ writes output to a file
Answer: b
24. What is the difference between ‘eq’ and ‘cmp’ in Perl?
a. ‘eq’ is used for numerical comparison, while ‘cmp’ is used for string comparison
b. ‘eq’ is used for case-sensitive string comparison, while ‘cmp’ is used for case-insensitive string comparison
c. ‘eq’ is used for string comparison, while ‘cmp’ is used for numerical comparison
d. ‘eq’ is used for case-sensitive string comparison, while ‘cmp’ is used for case-sensitive string comparison
Answer: d
25. What is the difference between ‘qw’ and ‘q’ in Perl?
a. ‘qw’ is used to quote a list of words, while ‘q’ is used to quote a single string
b. ‘q’ is used to quote a list of words, while ‘qw’ is used to quote a single string
c. ‘qw’ is used to quote a regular expression, while ‘q’ is used to quote a list of words
d. ‘q’ is used to quote a regular expression, while ‘qw’ is used to quote a list of words
Answer: a
26. Which function is used to remove an element from an array in Perl?
a. remove()
b. delete()
c. splice()
d. pop()
Answer: c
27. What is the Perl equivalent of a while loop in other programming languages?
a. while (condition) { }
b. do { } while (condition)
c. until (condition) { }
d. for (my $i=0; $i<=10; $i++) { }
Answer: a
28. What is the difference between ‘grep’ and ‘map’ functions in Perl?
a. ‘grep’ filters the elements of an array based on a condition, while ‘map’ applies a function to each element of an array
b. ‘grep’ applies a function to each element of an array, while ‘map’ filters the elements of an array based on a condition
c. Both functions are used to filter the elements of an array based on a condition
d. Both functions are used to apply a function to each element of an array
Answer: a
29. What does the ‘undef’ function do in Perl?
a. Defines a variable
b. Deletes a variable
c. Sets a variable to a null value
d. Sets a variable to an undefined value
Answer: d
30. What is the Perl equivalent of a try-catch block in other programming languages?
a. eval { }, die { }
b. try { }, catch { }
c. if { }, else { }
d. for { }, foreach { }
Answer: a
31. What is the difference between ‘splice’ and ‘slice’ functions in Perl?
a. ‘splice’ removes elements from an array, while ‘slice’ returns a subset of elements from an array
b. ‘splice’ returns a subset of elements from an array, while ‘slice’ removes elements from an array
c. Both functions are used to remove elements from an array
d. Both functions are used to return a subset of elements from an array
Answer: a
32. What is the difference between ‘exists’ and ‘defined’ functions in Perl?
a. ‘exists’ checks whether a hash key exists, while ‘defined’ checks whether a variable is defined
b. ‘exists’ checks whether an array element exists, while ‘defined’ checks whether a variable is defined
c. ‘exists’ checks whether a variable is defined, while ‘defined’ checks whether a hash key exists
d. ‘exists’ checks whether a subroutine exists, while ‘defined’ checks whether a variable is defined
Answer: a
33. Which function is used to concatenate two strings in Perl?
a. concat()
b. join()
c. merge()
d. . (dot)
Answer: d
34. Which function is used to replace a pattern in a string with another string in Perl?
a. replace()
b. swap()
c. substitute()
d. s///
Answer: d
35. What does the ‘do’ block do in Perl?
a. Defines a subroutine
b. Runs an external program
c. Executes a group of statements
d. Imports a module
Answer: c
36. What is the Perl equivalent of a ternary operator in other programming languages?
a. if-elsif-else chain
b. when-otherwise chain
c. either-or chain
d. ?:
Answer: d
37. What is the Perl equivalent of a do-while loop in other programming languages?
a. while (condition) { }, do { } while (condition)
b. do { } until (condition), while (condition) { }
c. for (my $i=0; $i<=10; $i++) { }, do { } while (condition)
d. until (condition) { }, do { } while (condition)
Answer: b
38. What is the Perl equivalent of a continue statement in other programming languages?
a. next
b. redo
c. last
d. continue
Answer: b
39. What is the Perl equivalent of a break statement in other programming languages?
a. next
b. last
c. continue
d. break
Answer: b
40. Which function is used to convert a string to lowercase or uppercase in Perl?
a. upper()
b. lower()
c. lc()
d. uc()
Answer: c
41. Which function is used to get the current time in seconds in Perl?
a. time()
b. current_time()
c. current_sec()
d. clock()
Answer: a
42. What does the ‘each’ function do in Perl?
a. Returns the number of elements in a hash
b. Returns the value of the current hash element
c. Returns the key of the current hash element
d. Returns the index of the current array element
Answer: c
43. What is the difference between ‘push’ and ‘unshift’ functions in Perl?
a. ‘push’ adds elements to the end of an array, while ‘unshift’ adds elements to the beginning of an array
b. ‘push’ adds elements to the beginning of an array, while ‘unshift’ adds elements to the end of an array
c. ‘push’ removes elements from the beginning of an array, while ‘unshift’ removes elements from the end of an array
d. ‘push’ removes elements from the end of an array, while ‘unshift’ removes elements from the beginning of an array
Answer: a
44. What is the difference between ‘and’ and ‘&&’ operators in Perl?
a. ‘and’ evaluates both operands, while ‘&&’ short-circuits the evaluation if the first operand is false
b. ‘&&’ evaluates both operands, while ‘and’ short-circuits the evaluation if the first operand is false
c. Both operators evaluate both operands
d. Both operators short-circuit the evaluation if the first operand is false
Answer: a
45. What is the difference between ‘or’ and ‘||’ operators in Perl?
a. ‘or’ evaluates both operands, while ‘||’ short-circuits the evaluation if the first operand is true
b. ‘||’ evaluates both operands, while ‘or’ short-circuits the evaluation if the first operand is true
c. Both operators evaluate both operands
d. Both operators short-circuit the evaluation if the first operand is true
Answer: a
46. What is the Perl equivalent of a multi-dimensional array in other programming languages?
a. Array of arrays
b. Hash of arrays
c. Array of hashes
d. Hash of hashes
Answer: a
47. How do you declare a Perl hash?
a. var %hash = ();
b. my %hash = ();
c. %hash = ();
d. hash = {}
Answer: b
48. Which function is used to change the case of the first letter of a string in Perl?
a. ucfirst()
b. capitalize()
c. upcase()
d. firstcap()
Answer: a
49. Which function is used to get the size of an array or hash in Perl?
a. length()
b. size()
c. count()
d. scalar()
Answer: d
50. Which function is used to pad a string with spaces or other characters in Perl?
a. pad()
b. space()
c. fill()
d. sprintf()