PrepIQ Perl Programming Ultimate Exam, Exams of Technology

Aimed at individuals learning Perl, this practice exam covers topics such as variables, control structures, regular expressions, file handling, and advanced Perl techniques. Great for those preparing for certification or professional roles requiring Perl expertise.

Typology: Exams

2025/2026

Available from 05/03/2026

shilpi-jain-3
shilpi-jain-3 🇮🇳

2.5

(11)

80K documents

1 / 88

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PrepIQ Perl Programming Ultimate
Exam
**Question 1.** Which pragma forces you to declare variables before using
them?
A) use warnings;
B) use strict;
C) use feature;
D) use lib;
Answer: B
Explanation: `use strict;` enables strict mode, requiring explicit variable
declaration with `my`, `our`, or `local`.
**Question 2.** What does the `-p` command-line option do when running a
Perl one-liner?
A) Prints each line after applying the script, looping automatically.
B) Executes the script without printing anything.
C) Enables automatic line numbering.
D) Runs the script in parallel mode.
Answer: A
Explanation: `-p` wraps the script in a `while (<>) { … } continue { print; }`
loop, printing each processed line.
**Question 3.** In Perl, which sigil is used for scalar variables?
A) @
B) %
C) $
D) &
Answer: C
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58

Partial preview of the text

Download PrepIQ Perl Programming Ultimate Exam and more Exams Technology in PDF only on Docsity!

Exam

Question 1. Which pragma forces you to declare variables before using them? A) use warnings; B) use strict; C) use feature; D) use lib; Answer: B Explanation: use strict; enables strict mode, requiring explicit variable declaration with my, our, or local. Question 2. What does the -p command-line option do when running a Perl one-liner? A) Prints each line after applying the script, looping automatically. B) Executes the script without printing anything. C) Enables automatic line numbering. D) Runs the script in parallel mode. Answer: A Explanation: -p wraps the script in a while (&lt;&gt;) { … } continue { print; } loop, printing each processed line. Question 3. In Perl, which sigil is used for scalar variables? A) @ B) % C) $ D) & Answer: C

Exam

Explanation: The dollar sign $ denotes a scalar, which holds a single value (string, number, or reference). Question 4. Which operator concatenates two strings? A). B) + C) :: D) => Answer: A Explanation: The dot . operator joins two strings together. Question 5. What is the result of the expression 5. 3 in Perl? A) 8 B) 53 C) 5. D) Syntax error Answer: B Explanation: The . operator concatenates, so 5. 3 yields the string "53". Question 6. Which function returns the number of elements in an array when used in scalar context? A) size() B) length() C) scalar() D) @array Answer: C

Exam

Answer: B Explanation: chomp removes a trailing input record separator (usually newline) from a string, defaulting to $_. Question 10. Which of the following is true about the undef value? A) It is the same as an empty string. B) It evaluates to false in boolean context. C) It can be used as a hash key. D) It triggers a runtime error when printed. Answer: B Explanation: undef represents an undefined value and evaluates to false; printing it yields an empty string with a warning if use warnings is enabled. Question 11. How do you create an anonymous array containing the numbers 1, 2, and 3? A) (1, 2, 3) B) [1, 2, 3] C) {1, 2, 3} D) [1, 2, 3] Answer: B Explanation: Square brackets [] create an anonymous array reference. Question 12. Given my $ref = \@array;, how would you access the third element of @array through $ref? A) $ref->[2] B) $ref{2} C) $$ref[2] D) $ref[2]

Exam

Answer: A Explanation: Arrow notation -&gt; dereferences an array reference; indices are zero-based. Question 13. Which regular-expression modifier makes the match case-insensitive? A) g B) i C) s D) m Answer: B Explanation: The i modifier tells the pattern engine to ignore case differences. Question 14. What does the pattern /\d+/ match? A) One or more digits. B) Exactly one digit. C) Zero or more digits. D) Any non-digit character. Answer: A Explanation: \d is a digit character class; + quantifier means “one or more”. Question 15. Which operator performs a global substitution on a string? A) s///g B) tr///g C) m///g

Exam

C) $s =~ tr/a/b/g; D) $s =~ s/a/b/; Answer: C Explanation: The tr/// operator performs character translation; the g flag is implicit for tr. Question 19. Which of the following file test operators checks if a file is executable? A) -x B) -e C) -f D) -r Answer: A Explanation: -x returns true if the file is executable by the real UID/GID. Question 20. What does the opendir function return on success? A) A filehandle. B) The number of entries. C) A boolean true. D) An array of filenames. Answer: C Explanation: opendir returns true on success; the directory handle is passed as the first argument. Question 21. Which special variable contains the exit status of the last executed external command? A) $! B) $@

Exam

C) $?

D) $^E

Answer: C Explanation: $? holds the status returned by system, backticks, or exec. Question 22. Which module provides the find function for traversing directory trees? A) Cwd B) File::Find C) Dir::Traverse D) IO::Dir Answer: B Explanation: File::Find exports find to recursively process directories. Question 23. What is the purpose of the bless function in Perl OOP? A) To create a hash reference. B) To turn a reference into an object of a given class. C) To destroy an object. D) To copy an object. Answer: B Explanation: bless associates a reference with a package name, making it an object of that class. Question 24. Which statement correctly defines a package named Animal? A) package Animal; B) sub Animal { … }

Exam

C) The current package’s symbols. D) The list of lexical variables. Answer: B Explanation: @_ holds the arguments supplied when the subroutine is called. Question 28. Which keyword creates a lexical variable that is scoped to the current block? A) local B) my C) our D) state Answer: B Explanation: my declares a lexically scoped variable visible only within the enclosing block. Question 29. In list context, what does the keys %hash expression return? A) A list of key/value pairs. B) The number of keys. C) A list of all keys. D) A reference to the keys. Answer: C Explanation: keys %hash yields a list of the hash’s keys when evaluated in list context. Question 30. Which operator would you use to test whether a key exists in a hash %h?

Exam

A) defined %h{'key'} B) exists $h{'key'} C) exists $h{'key'}; D) exists $h{'key'}; Answer: B Explanation: exists $h{'key'} checks if the specified key is present in the hash. Question 31. What does the map function do? A) Filters a list based on a condition. B) Transforms each element of a list and returns a new list. C) Sorts a list. D) Removes duplicate elements. Answer: B Explanation: map { BLOCK } LIST applies the BLOCK to each element, returning the transformed list. Question 32. Which of the following statements about Perl’s context sensitivity is FALSE? A) In scalar context, localtime returns a formatted string. B) In list context, localtime returns a nine-element list. C) The grep function always returns a list regardless of context. D) scalar(@array) gives the number of elements. Answer: C Explanation: In scalar context, grep returns the count of matching elements, not a list.

Exam

Question 36. What does the last keyword do inside a loop? A) Restarts the loop from the beginning. B) Skips the current iteration. C) Exits the loop immediately. D) Prints the loop index. Answer: C Explanation: last terminates the innermost loop. Question 37. Which loop construct is equivalent to for (my $i=0;$i&lt;10;$i++) { … }? A) foreach (0..9) { … } B) while ($i<10) { … $i++; } C) do { … } while ($i<10); D) All of the above. Answer: A Explanation: foreach (0..9) iterates over the list of numbers 0 through 9, matching the C-style loop. Question 38. How can you label a loop to allow next or last to affect an outer loop? A) label: while (…) { … } B) while (label) { … } C) label while (…) { … } D) while (…) label { … } Answer: A

Exam

Explanation: label: while (…) { … } defines a loop label; next LABEL; or last LABEL; can control it. Question 39. Which statement correctly creates a hash with keys a and b and values 1 and 2? A) %h = (a => 1, b => 2); B) %h = ("a",1,"b",2); C) %h = (a,1,b,2); D) All of the above. Answer: D Explanation: All three syntaxes produce the same hash; the fat comma =&gt; auto-quotes barewords. Question 40. What does the each %hash function return in list context? A) A list of all keys. B) A list of all values. C) A two-element list (key, value) on each call, iterating through the hash. D) The number of key/value pairs. Answer: C Explanation: each returns a pair (key, value) each time it is called, maintaining internal iterator state. Question 41. Which of the following is the correct way to enable the say feature without importing the entire feature pragma? A) use feature 'say'; B) use warnings 'say'; C) use strict 'say'; D) use perl5i;

Exam

B) 1..

C) 15

D) Error Answer: A Explanation: scalar @a returns the number of elements, which is 5. Question 45. Which of the following regular-expression constructs matches a word boundary? A) \b B) ^ C) $ D) \w Answer: A Explanation: \b asserts a position between a word character and a non-word character. Question 46. In the substitution s/foo/bar/e;, what does the e modifier do? A) Makes the replacement case-insensitive. B) Evaluates the replacement as Perl code. C) Performs the substitution globally. D) Stops after the first match. Answer: B Explanation: The e flag treats the replacement string as an expression and evaluates it. Question 47. Which function returns the length of a string $str?

Exam

A) size($str) B) len($str) C) length($str) D) count($str) Answer: C Explanation: length returns the number of characters in a string. Question 48. Which statement correctly creates a reference to a scalar $x? A) $ref = &amp;$x; B) $ref = %x; C) $ref = $x; D) $ref = *x; Answer: C Explanation: The backslash creates a reference; \$x is a scalar reference. Question 49. How would you dereference an array reference $aref to obtain the second element? A) $aref->[1] B) $$aref[1] C) $aref[1] D) Both A and B Answer: D Explanation: Both $aref-&gt;[1] and $$aref[1] correctly dereference the array reference. Question 50. Which module provides the new method for creating objects in a modern OOP style?

Exam

Question 53. Which of these is a valid shebang line for a Perl script on a Unix system? A) #!/usr/bin/perl B) #!perl C) #!/bin/perl -w D) Both A and C Answer: D Explanation: Both #!/usr/bin/perl and #!/bin/perl -w are valid shebang lines specifying the interpreter. Question 54. What does the -M command-line option do? A) Enables warnings. B) Loads a module before executing the script. C) Sets the memory limit. D) Runs the script in debug mode. Answer: B Explanation: -MModule is equivalent to use Module; and loads the module at compile time. Question 55. Which of the following statements about the given/when construct is TRUE in Perl 5.10+? A) It replaces the switch statement from C. B) It automatically enables strict mode. C) when can take a regular expression without $_ =~. D) given creates a new lexical scope for its block. Answer: C Explanation: In given ($var) { when /regex/ { … } }, when implicitly matches $_ against the pattern.

Exam

Question 56. Which function would you use to change the current working directory to /tmp? A) chdir('/tmp'); B) cd('/tmp'); C) setdir('/tmp'); D) dir('/tmp'); Answer: A Explanation: chdir changes the process’s working directory. Question 57. What does the -T file test operator check? A) If a file is a text file. B) If a file is a symbolic link. C) If a file is a directory. D) If a file is empty. Answer: A Explanation: -T heuristically determines whether a file appears to be text. Question 58. Which of the following is the correct way to read an entire file into a scalar $data? A) local $/; $data = ; B) $data = join('', ); C) $data = do { local $/; }; D) All of the above. Answer: D Explanation: All three approaches slurp the file by undefining the input record separator.