Perl MCQ Questions and Answers

Perl MCQ Questions and Answers

Perl Questions and Answers contain set of 10 Perl MCQ questions with answers which will help you to clear beginner level Perl quiz.

1. The statement open(FH,”abc.txt”) will :

  1. Opens the file abc.txt for overwriting.
  2. Opens the file abc.txt for reading.
  3. Contains an error, so won’t compile.
  4. Opens the file abc.txt for appending.

2. Which of the following is used in perl?

  1. elseif
  2. else if
  3. elsif
  4. else-if

3. What will be printed by the code below :
my $val = {};
print ref($val);
 

  1. Array value
  2. Hash value
  3. Scalar value
  4. Empty value

4. What will be printed in the below code :
my @array = (0,1,2);
my $val = @array;
print “$val”;

  1. 0 1 2
  2. 0
  3. 3
  4. Error code

5. In Perl, scalar variables always start with a __________.

  1. %
  2. #
  3. $
  4. @

6. In Perl, the words function and subroutines are used interchangeably.

  1. True
  2. False

7. What gets printed for the code :
my  $string = ‘a\\b\n’;
print  $str;
 

  1. a\\b\n
  2. ab (newline)
  3. a\b\n
  4. a\\b (newline)

8. What will be printed :
print ‘a’;
BEGIN {
            print ‘b’;
}
sub foo {
            print ‘c’;
}
 

  1. abc
  2. bca
  3. ba
  4. ab

9. Which of the following special variable is not related to regular expression matches?

  1. $_
  2. $’
  3. $&
  4. $`

10. The argument ‘-d’ in Perl stands for debug.

  1. True
  2. False