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.

Questions and Answers

Perl Mock Test IV

Q 1 - Parameters of a function can be acessed inside the function using the special array @_?

A - true

B - false

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?

A - Using args

B - using scalar(@_)

C - Both of the above.

D - None of the above.

Answer : B

Explanation

using scalar(@_), we can get the total number of arguments passed.

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.

Q 4 - What is the default scope of perl variables?

A - global

B - private

C - protected

D - friend

Answer : A

Explanation

By default, all variables in Perl are global variables, which means they can be accessed from anywhere in the program.

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?

A - my

B - local

C - state

D - None of the above.

Answer : B

Explanation

The local is used when the current value of a variable must be visible to called subroutines.

Q 12 - Which of the following function deletes a file?

A - delete

B - unlink

C - seek

D - None of the above.

Answer : B

Explanation

unlink − used to delete a file.

Q 13 - Which of the following function opens a file in read-only mode?

A - open(DATA, "<file.txt");

B - open(DATA, ">file.txt");

C - open(DATA, "+>file.txt");

D - None of the above.

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?

A - open(DATA, "<file.txt");

B - open(DATA, ">file.txt");

C - open(DATA, "+<file.txt");

D - None of the above.

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?

A - open(DATA, "<file.txt");

B - open(DATA, ">file.txt");

C - open(DATA, "+<file.txt");

D - None of the above.

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?

A - close

B - unlink

C - seek

D - None of the above.

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?

A - close

B - getc

C - seek

D - None of the above.

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?

A - rename

B - tell

C - seek

D - None of the above.

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?

A - rename

B - tell

C - seek

D - None of the above.

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?

A - rename

B - tell

C - seek

D - None of the above.

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?

A - $ref = \$foo;

B - $ref = \@ARGV;

C - $ref = \%ENV;

D - $ref = \&PrintHash;

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?

A - $ref = \$foo;

B - $ref = \@ARGV;

C - $ref = \%ENV;

D - $ref = \&PrintHash;

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?

A - $ref = \$foo;

B - $ref = \@ARGV;

C - $ref = \%ENV;

D - $ref = \&PrintHash;

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?

A - $ref = \$foo;

B - $ref = \@ARGV;

C - $ref = \%ENV;

D - $ref = \&PrintHash;

Answer : D

Explanation

You can create a reference for any subroutine by prefixing it with a backslash as follows - $ref = \&PrintHash;

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
perl_questions_answers.htm
Advertisements