Perl Online Quiz



Following quiz provides Multiple Choice Questions (MCQs) related to Perl. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - Which of the following data types are preceded by an "at" sign (@) in Perl?

A - Scalar

B - Array

C - Hashes

D - All of the above.

Answer : B

Explanation

Arrays are preceded by an "at" sign (@).

Q 2 - In which of the following variable context, assignment to an array or a hash evaluates the right-hand side in a list context?

A - Scalar

B - List

C - Boolean

D - Void.

Answer : B

Explanation

List − Assignment to an array or a hash evaluates the right-hand side in a list context.

Q 3 - Which of the following method prepends list to the front of the array, and returns the number of elements in the new array?

A - push @ARRAY, LIST

B - pop @ARRAY

C - shift @ARRAY

D - unshift @ARRAY, LIST

Answer : D

Explanation

unshift @ARRAY, LIST - Prepends list to the front of the array, and returns the number of elements in the new array.

Q 4 - Which of the following statement restarts the loop block without evaluating the conditional again?

A - next

B - last

C - continue

D - redo

Answer : D

Explanation

redo statement − The redo command restarts the loop block without evaluating the conditional again. The continue block, if any, is not executed.

Q 5 - Which of the following statement repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body?

A - while

B - until

C - for

D - None of the above.

Answer : A

Explanation

while loop − Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.

Q 6 - Which of the following operator returns true if the left argument is stringwise greater than the right argument?

A - lt

B - gt

C - le

D - ge

Answer : B

Explanation

gt − Returns true if the left argument is stringwise greater than the right argument.

Q 7 - Which of the following operator returns true if the left argument is stringwise not equal to the right argument?

A - eq

B - ne

C - cmp

D - ge

Answer : B

Explanation

ne − Returns true if the left argument is stringwise not equal to the right argument.

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 9 - 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 10 - 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;

perl_questions_answers.htm
Advertisements