- Perl Basics
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
- Perl - Operators
- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl Advanced
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Useful Resources
- Perl - Discussion
Perl Mock Test
This section presents you various set of Mock Tests related to Perl. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.
Perl Mock Test IV
Q 1 - Parameters of a function can be acessed inside the function using the special array @_?
Answer : A
Explanation
Parameters can be acessed inside the function using the special array @_. Thus the first argument to the function is in $_[0], the second is in $_[1], and so on.
Q 2 - How will you get the count of parameters passed to a perl subroutine?
Answer : B
Explanation
using scalar(@_), we can get the total number of arguments passed.
Q 3 - Which of the following is true about my operator?
B - Outside confined region , my variable cannot be used or accessed.
Answer : C
Explanation
The my operator confines a variable to a particular region of code in which it can be used and accessed. Outside that region, this variable cannot be used or accessed.
Answer : A
Explanation
By default, all variables in Perl are global variables, which means they can be accessed from anywhere in the program.
Q 5 - Which of the following is correct about lexical variables?
A - Lexical variables are private variables created using my operator.
Answer : A
Explanation
Lexical variables are private variables created using my operator.
Q 6 - Which of the following operator is used when the current value of a variable must be visible to called subroutines?
Answer : B
Explanation
The local is used when the current value of a variable must be visible to called subroutines.
Q 7 - Which of the following is true about lexical scoping?
Answer : D
Explanation
All of the above options are correct.
Q 8 - Which of the following is true about state variables?
B - These variables are defined using the state operator and available starting from Perl 5.9.4.
Answer : C
Explanation
Both of the above options are correct.
Q 9 - Which of the following is true about state variables?
B - These variables are defined using the state operator and available starting from Perl 5.9.4.
Answer : C
Explanation
Both of the above options are correct.
Q 10 - Which of the following is true about Subroutine Call Context?
Answer : C
Explanation
Both of the above options are correct.
Q 11 - Which of the following is true about Perl references?
B - Because of its scalar nature, a reference can be used anywhere, a scalar can be used.
Answer : C
Explanation
Both of the above options are correct.
Q 12 - Which of the following function deletes a file?
Answer : B
Explanation
unlink − used to delete a file.
Q 13 - Which of the following function opens a file in read-only mode?
Answer : A
Explanation
open(DATA, "<file.txt"); − opens a file in read-only mode.
Q 14 - Which of the following function opens a file in writing mode after truncating the file?
Answer : B
Explanation
open(DATA, ">file.txt"); − opens a file in writing mode after truncating the file.
Q 15 - Which of the following function opens a file in writing mode without truncating the file?
Answer : C
Explanation
open(DATA, "+<file.txt"); − opens a file in writing mode without truncating the file.
Q 16 - Which of the following function disassociate the filehandle from the corresponding file?
Answer : A
Explanation
close − To close a filehandle, and therefore disassociate the filehandle from the corresponding file, you use the close function. This flushes the filehandle's buffers and closes the system's file descriptor.
Q 17 - Which of the following function returns a single character from the specified FILEHANDLE, or STDIN if none is specified?
Answer : B
Explanation
The getc function returns a single character from the specified FILEHANDLE, or STDIN if none is specified.
Q 18 - Which of the following function renames existing file?
Answer : A
Explanation
Function rename takes two arguments and it just rename existing file.
Q 19 - Which of the following function returns current position of a pointer in a file?
Answer : B
Explanation
You can use tell function to know the current position of a file.
Q 20 - Which of the following function points current position of a pointer to a particular position in a file?
Answer : C
Explanation
You can use seek function to point a particular position inside the file.
Q 21 - Which of the following code create a reference for a variable?
Answer : A
Explanation
You can create a reference for any variable by prefixing it with a backslash as follows - $ref = \$foo;
Q 22 - Which of the following code create a reference for a array?
Answer : B
Explanation
You can create a reference for any array by prefixing it with a backslash as follows - $ref = \@ARGV;
Q 23 - Which of the following code create a reference for a hash?
Answer : C
Explanation
You can create a reference for any hash by prefixing it with a backslash as follows - $ref = \%ENV;
Q 24 - Which of the following code create a reference for a subroutine?
Answer : D
Explanation
You can create a reference for any subroutine by prefixing it with a backslash as follows - $ref = \&PrintHash;
Q 25 - Which of the following is true about dereferencing?
A - Dereferencing returns the value from a reference point to the location.
Answer : C
Explanation
Both of the above options are correct.
Answer Sheet
Question Number | Answer Key |
---|---|
1 | A |
2 | B |
3 | C |
4 | A |
5 | A |
6 | B |
7 | D |
8 | C |
9 | C |
10 | C |
11 | C |
12 | B |
13 | A |
14 | B |
15 | C |
16 | A |
17 | B |
18 | A |
19 | B |
20 | C |
21 | A |
22 | B |
23 | C |
24 | D |
25 | C |