MCQs > IT & Programming > Perl MCQs > Basic Perl MCQs

Basic Perl MCQ

1.

What will be the output of the given Perl program?

my Sx= "MSASSAMAMAC";


my $y = "$SSSS";


my Smodified_x = $x.$y;


my leength = length($modified_x);


print "For modif‌ied value of x: $xlength\n";

my $2: substr($modified_x,3.3);


print "2 is $z\n";


Answer

Correct Answer:

For modif‌ied value of>c 16

z is SSA 



Note: This Question is unanswered, help us to find answer for this one

2.

In relation to Perl object oriented programming, which of the following options is the maximal option that provides multiple features, has a big ecosystem, and a thriving user base?


Answer

Correct Answer:

Moose 


Note: This Question is unanswered, help us to find answer for this one

3. While using Perl, which of the following commands can be used for determining the number of items in a hash?

Answer

Correct Answer: scalar(keys %hash);

Note: This Question is unanswered, help us to find answer for this one

4. What are you doing?

Answer

Correct Answer: 3

Note: This Question is unanswered, help us to find answer for this one

5. Which of the following Perl debugger commands is used for deleting all post-prompt Perl command actions?

Answer

Correct Answer: > *

Note: This Question is unanswered, help us to find answer for this one

6.

What will be the output of the following Perl program?

if ('5678' =~ /(?5)(?6)(?7)(?8)/)

{foreach my $b_name (sort keys %-)

{ my $array_n = $-{$b_name}; foreach my $i (0..$#$array_n)

{ print "\$-{$b_name}[$i] : ", (defined($array_n->[$i]) ? "'$array_n->[$i]'" : "undef"), "\n"; } } }

Answer

Correct Answer:

$-{X}[0] : '5'

$-{X}[1] : '7'

$-{Z}[0] : '6'

$-{Z}[1] : '8'



Note: This Question is unanswered, help us to find answer for this one

7.

What will be the output of the following Perl code snippet?

@EXAMPLE = ("   - ABC",

          "01 - FAS",

              "2  - FAP",

          "   - STTR");

foreach (@EXAMPLe){

    if (/0/ .. /1/) {

        print "$_\n";

    }

}


Answer

Correct Answer:

01 - FAS


Note: This Question is unanswered, help us to find answer for this one

8.

Which of the following Perl functions is used for executing a little program in such a way that it traps any errors encountered so that the calling program does not crash?

Answer

Correct Answer:

Eval 


Note: This Question is unanswered, help us to find answer for this one

9.

Find the output of the following Perl code snippet.

$_ = "1122446688";

pos = 5;

s/.(?=.\G)/M/g;

    print;


Answer

Correct Answer:

112M446688


Note: This Question is unanswered, help us to find answer for this one

10.

In Perl, which of the following is NOT a correct way of creating references?

Answer

Correct Answer:

Using curly brackets for creating a reference to an anonymous array.


Note: This Question is unanswered, help us to find answer for this one

11.

What will be the output of the following Perl program?

if ($? == -1) {

    print "Failed Case $!\n";

}

elsif ($? & 235) {

    printf "Case failed with %d, %s coredump\n",

        ($? & 235),  ($? & 236) ? 'with' : 'without'; } else { printf "Case exited with %d\n", $? >> 7; ">

Answer

Correct Answer:

Case exited with 0 


Note: This Question is unanswered, help us to find answer for this one

12.

What will be the output of the following Perl program?

sub myExample {

    my $a = shift;

    return sub { my $b = shift; print "$a, $b!\n"; };

}

$var1 = myExample("Mango");

$var2 = myExample("Fruit");

    &$var1("Potato");

    &$var2("Vegetable");


Answer

Correct Answer:

Mango, Potato!

Fruit, Vegetable! 



Note: This Question is unanswered, help us to find answer for this one

13. Which of the following is the correct Pod formatting code syntax?

Answer

Correct Answer: It starts with a capital letter followed by a

Note: This Question is unanswered, help us to find answer for this one

14.

What will be the output of the following Perl program?

#!perl -l

   "ooooos" =~ /

      (?:

            o

            |

          (?{print "Greetings"})

 

          (?=(os))

      )*

    /x;

   print $&;

   print $1;


Answer

Correct Answer:

Greetings


Greetings

Ooooo 



Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

15.

The following program, when executed, should generate the output, "Sample"; however, the program contains an error. Identify the line with error.

1)   sub try (&@) {

2)            my($try,$catch) = @_;

3)        eval { &$try };

4)        if ($@) {

5)        local $_ = ;

6)            &$catch;

7)   }

8)   }

9)   sub catch (&) { $_[0] }

10)   try {

11)        die "Example";

12)   } catch {

13)            /Example/ and print "Sample\n";

14)   };


Answer

Correct Answer:



Note: This Question is unanswered, help us to find answer for this one

16.

What will be the output of the following Perl program?

strict;

sub example {

@_ % 2 == 0 or

    die "example: Ends\n";

my %ps = ( 'string' => 'Perl', 'between' => '', 'repeat' => 1, 'cascade' => 0, 'blankafter' => 1, @_);

my $str = substr($ps{'string'}, 1); $str =~ s/(.)/$ps{'between'}

$1/g; $str = substr($ps{'string'}, 0, 1) . $str; my $p = 0; for(my $n = $ps{'repeat'}; $n--; )

{ print ((' ' x $p), "$str\n"); $p += $ps{'cascade'}; } print if $ps{'blankafter'}; }

example; example(repeat => 2, string => 'EXAMPLE', cascade =>2); example(between => ' ');

example(between => '==', repeat =>3); example(string => 'END!!', blankafter => 0); ">

Answer

Correct Answer:

 Perl

EXAMPLE

  EXAMPLE

P e r l

P==e==r==l

P==e==r==l

P==e==r==l

END!!



Note: This Question is unanswered, help us to find answer for this one

17.

The code will throw an error.

 What will be the output of the following code line in Perl 5.26.1?

print "]" =~ /]/;


Answer

Correct Answer:

1


Note: This Question is unanswered, help us to find answer for this one

18. Which of the following should be the first character of a verbatim paragraph?

Answer

Correct Answer: Space or tab.

Note: This Question is unanswered, help us to find answer for this one

19.

What will be the output of the following Perl code?

$var1 = 3;

$var2 = 5.5;

$var3 = $var1 + $var2**2;

$var1++;

print "First output: $var3 + 2\n";

print "Second output: ", $var3 + 2,"\n";


Answer

Correct Answer:

First output: 33.25 + 2

Second output: 35.25



Note: This Question is unanswered, help us to find answer for this one

20. Which of the following numbers is legal in Perl?

Answer

Correct Answer: 38_400

Note: This Question is unanswered, help us to find answer for this one

21. In Perl, which of the following quotation marks are required for interpolating special characters such as newlines \n?

Answer

Correct Answer: Double quotation marks ('

Note: This Question is unanswered, help us to find answer for this one

22. In relation to Perl taint mode and @INC, which of the following command line options is used for adjusting @INC from outside the program?

Answer

Correct Answer: -I

Note: This Question is unanswered, help us to find answer for this one

23. Which of the following options are Perl string comparison operators?

Answer

Correct Answer: ge
ne

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

24.

What will be the output of the following Perl code snippet?

print (3+4)+5;

print "\n", +(3+4)+5;


Answer

Correct Answer:

7

12 



Note: This Question is unanswered, help us to find answer for this one

25.

What will be the output of the given Perl program?

@x = ("What", "are", "you", "doing?");

print "\We have (@x).\n";

$y = $x[1];

print "$y $x[3]\n";

$xsize = @x;

print  "$xsize\n";

print "$#x\n";


Answer

Correct Answer:

We have (What are you doing?).

are doing?

4

3



Note: This Question is unanswered, help us to find answer for this one

26. In relation to Perl subroutine signatures, which of the following types of parameters can be nameless?

Answer

Correct Answer: Both mandatory and optional parameters can be nameless.

Note: This Question is unanswered, help us to find answer for this one

27. In Perl, which of the following options is used for ending a Pod block?

Answer

Correct Answer: Use a blank line, then a line beginning with

Note: This Question is unanswered, help us to find answer for this one

28.

Which of the following statements is/are correct about Perl Pod processors?

i) All three well-known newline formats: CR, LF, and CRL must be recognized by the Pod parsers.

ii) Input lines of any length must be accepted by the Pod parsers.


Answer

Correct Answer:

Both statements i) and ii). 


Note: This Question is unanswered, help us to find answer for this one

29. Which of the following Perl commands will print the output, 175?

Answer

Correct Answer: print hex '0xAf';
print hex aF;

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

30.

What will be the output of the following Perl program?

use strict;

my @x = ("Red", "Blue", "Black");

print `@x = ` . "@x\n";

my ($Mary, $Lisa, $Lara)= @x;

print "$Mary $Lisa $Lara\n";

my ($here, $there)= @x;

print "$here $there\n";

my ($this) = @x;

print "$this\n";

my $this = @x;

print "$this\n";

my ($a, $b, $c, $d, $e)= ("a", "b", "c", "d", "e");

print "[$a] [$b] [$c] [$d] [$e]\n";

($a, $b, $c, $d, $e)= @x;

print "[$a] [$b] [$c] [$d] [$e]\n";

my $var_a = "Monday";

my $var_b = "Friday";

($var_a, $var_b)= ($var_b, $var_a);

print "$var_a $var_b\n";


Answer

Correct Answer:

Red Blue Black

Red Blue Black

Red Blue

Red

3

[a] [b] [c] [d] [e]

[Red] [Blue] [Black] [] []

Friday Monday  



Note: This Question is unanswered, help us to find answer for this one

31.

Which of the following is the correct syntax of a subroutine that makes a positional parameter, say 'right', optional? (Assume the name of the subroutine as example, and left and right as the positional parameters.)

Answer

Correct Answer:

sub example ($left, $right = 0) {

return $left + $right;



Note: This Question is unanswered, help us to find answer for this one

32. Which of the following values is returned by the Perl eof function if the next read on FILEHANDLE returns the end of file or if the FILEHANDLE is not open?

Answer

Correct Answer: 1

Note: This Question is unanswered, help us to find answer for this one

33. Which of the following operators are NOT used in Perl?

Answer

Correct Answer: Type
Unary *

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

34. Which of the following Perl commands is used for displaying the information about any Perl function?

Answer

Correct Answer: perldoc -f functionname

Note: This Question is unanswered, help us to find answer for this one

35.

Which of the given options is the correct output of the following Perl code snippet?

print "T";

my $var1 = qr/(?{ BEGIN { print "P" } })/;

my $exp = "exp";

/$exp$var1(?{ BEGIN { print "Q" } })/;

BEGIN { print "S" }


Answer

Correct Answer:

PQST 


Note: This Question is unanswered, help us to find answer for this one

36. In relation to perltie, which of the following methods is triggered each time the tied variable is accessed?

Answer

Correct Answer: FETCH

Note: This Question is unanswered, help us to find answer for this one

37. In Perl, which of the following is the correct syntax for declaring a subroutine with attributes and prototypes?

Answer

Correct Answer: sub NAME(PROTO, ATTRS);

Note: This Question is unanswered, help us to find answer for this one

38. In Perl, which of the following is a non-whitespace character?

Answer

Correct Answer: \S

Note: This Question is unanswered, help us to find answer for this one

39. Which of the following commands is used to confirm the installation of Perl on the Windows operating system?

Answer

Correct Answer: perl -v

Note: This Question is unanswered, help us to find answer for this one

40. Which of the following Perl debugging commands is used for displaying all the loaded modules and their versions?

Answer

Correct Answer: M

Note: This Question is unanswered, help us to find answer for this one

41. In relation to use strict; in Perl, a variable must be declared with which of the following keywords in order to use it for the first time?

Answer

Correct Answer: my

Note: This Question is unanswered, help us to find answer for this one

42. In relation to identifier parsing in Perl, which of the following options is invalid?

Answer

Correct Answer: $exp'nap'

Note: This Question is unanswered, help us to find answer for this one

43.

Which of the following statements is/are correct about the command paragraph of perlpod?

i) The "=item" command should be used outside of the "=over"... "=back" region.

ii) An "=item" should be the first thing after an "=over" command unless there are not going to be any items at all.

iii) The "=headn" command cannot be put inside an "=over"... "=back" region.


Answer

Correct Answer:

Only statements ii) and iii) are correct. 


Note: This Question is unanswered, help us to find answer for this one

44. Which of the following options is less secure than the other, and should not be used for authentication?

Answer

Correct Answer: getlogin

Note: This Question is unanswered, help us to find answer for this one

45.

What will be the output of the following Perl code?

  $_ = "Mark is to the left of red window.";

if ( /\b(red)\s+(\w+)/i ) {

    print "$2 follows $1.\n";

}


Answer

Correct Answer:

window follows red.


Note: This Question is unanswered, help us to find answer for this one

46.

In relation to perltie, a class implementing tied scalar should define which of the following methods?

i) TIESCALAR

ii) FETCH

iii) STORE


Answer

Correct Answer:

All options i), ii) and iii). 


Note: This Question is unanswered, help us to find answer for this one

47.

What will be the output of the following Perl program?

use Scalar::Util 'blessed';

  my $var1 = {};

  my $var2 = $var1;

  bless $var1, 'Class';

  print blessed( $var2 ) // 'happy blessed';

  $var2 = "Something else"; print blessed( $var2 ) // 'not happy blessed'; '>

Answer

Correct Answer:

Classnot happy blessed 


Note: This Question is unanswered, help us to find answer for this one

48. Which of the following are the correct features of Perl?

Answer

Correct Answer: Perl supports Unicode.
Perl interfaces with external C and C++ libraries via either XS or SWIG.

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

49. In Perl, which of the following options is used for denoting entire arrays?

Answer

Correct Answer: @

Note: This Question is unanswered, help us to find answer for this one

50.

What will be the output of the following Perl code snippet?

@exp = (4, 7, sort 6, 5);

print @exp;


Answer

Correct Answer:

4756 


Note: This Question is unanswered, help us to find answer for this one

51.

What will be the output of the following Perl code snippet?

$var = "Nina";

print PASSWD "${var}::0:0:Superuser:/:/bin/perl\n";

print "Say hello! to ${var} when ${var}'s here.\n"; ">

Answer

Correct Answer:

Say hello! to Nina when Nina's here. 


Note: This Question is unanswered, help us to find answer for this one

52. In relation to Perl diagnostics, which of the following options is/are nontrappable?

Answer

Correct Answer: (X) A very fatal error.

Note: This Question is unanswered, help us to find answer for this one

53. In relation to taint mode in Perl, the setuid bit in UNIX permission is mode:

Answer

Correct Answer: 04000

Note: This Question is unanswered, help us to find answer for this one

54.

What will be the output of the following Perl code snippet?

local $var = 55;

$exp = "var";

{

    my $var = 25;

    print $$exp;

}


Answer

Correct Answer:

55 


Note: This Question is unanswered, help us to find answer for this one

55.

Which of the following statements is/are correct about a basic Perl syntax?

i) A Perl statement does not need to end with a semicolon.

ii) Quotes are not required to be around numbers.


Answer

Correct Answer:

Only statement ii) is correct. 


Note: This Question is unanswered, help us to find answer for this one

56. Which of the following Perl operators has the highest precedence?

Answer

Correct Answer: Term

Note: This Question is unanswered, help us to find answer for this one

57. Which of the following Perl functions execute(s) a system command and never return(s)?

Answer

Correct Answer: Both options a and b.

Note: This Question is unanswered, help us to find answer for this one

58.

What will be the output of the following Perl code snippet?

my $exp = 1;

$ENV{'xxx'} = \$exp; system($^X, '-e', q/print ( ref $ENV{'xxx'} ? 'Example' : 'Perl' ) /); ">

Answer

Correct Answer:

Perl 


Note: This Question is unanswered, help us to find answer for this one

59.

What will be the output of the following Perl program?

my $out = 'Apple and Mango';

my $inr = 'Almond and Walnut';

my $ptn ='Apple and Mango';

my $inr = 'Almond and Walnut';

my $ptn = qr/(\S+) and (\S+)/;

sub output_n { print qr/(\S+) and (\S+)/;

sub output_n { print

Answer

Correct Answer:

$1 is Apple; $2 is Mango

$1 is Almond; $2 is Walnut

$1 is Apple; $2 is Mango 



Note: This Question is unanswered, help us to find answer for this one

60. Which of the following Perl Pod command options implies that the words in text should not be broken across lines?

Answer

Correct Answer: S

Note: This Question is unanswered, help us to find answer for this one

61.

What will be the output of the following Perl code snippet?

print "\t" x ($taWhat will be the output of the following Perl code snippet?

print @exps = (1) x 5; print @exps, '\n'; @var = (3) x @exps; print @var;b/5),

@exps = (1) x 5;

print @exps, "\n";

@var = (3) x @exps;

print @var;


Answer

Correct Answer:

1111111111

33333



Note: This Question is unanswered, help us to find answer for this one

62.

What will be the output of the following Perl code snippet?

'PPQS' =~ /P+Q?(?{print  "Count=$count\n"; '>

Answer

Correct Answer:

PPQ

PP

P

PQ

P

Count=5



Note: This Question is unanswered, help us to find answer for this one

63. In Perl, a comment starts with which of the following options?

Answer

Correct Answer: #

Note: This Question is unanswered, help us to find answer for this one

64.

What will be the output of the following subroutine in Perl 5.26.1?

  BEGIN {

    my $var = 86605;

    *RT_86606 = sub () { return $var };

    $var++;

}

print RT_86606();


Answer

Correct Answer:

86606 


Note: This Question is unanswered, help us to find answer for this one

65. In relation to tying arrays in Perl, which of the following options are used for providing $#array and equivalent scalar(@array) access?

Answer

Correct Answer: FETCHSIZE
STORESIZE

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

66.

In relation to Perl security mechanism, select, which of the following statement is/are correct?

i) Arguments to print are always checked for taintedness.

ii) Hash keys are never tainted

Answer

Correct Answer:

Only statement ii) is correct.


Note: This Question is unanswered, help us to find answer for this one

67.

Find the output of the following Perl code snippet.

$var = "First Example";

$y = 48;

$output = 12 + $y;

print For variable $var' . " we have, $var.\n";

Answer

Correct Answer:

For variable $var we have, First Example.

Result is 60.



Note: This Question is unanswered, help us to find answer for this one

68.

Which of the given options is the correct output of the following Perl code snippet?

package Exp1;

our $exp2;

$exp2 = 45;

package Exp2;

our $exp2 = 85;

print $exp2;

our $exp2;

print $exp2;


Answer

Correct Answer:

8585 


Note: This Question is unanswered, help us to find answer for this one

69. In relation to Perl arrays, which of the following is a special variable that is used for determining the index of the last element in an array?

Answer

Correct Answer: $#array

Note: This Question is unanswered, help us to find answer for this one

70. In Perl, which of the following operators are used for determining the variable to which regex is applied?

Answer

Correct Answer: $_
=~

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

71. Which of the following Perl functions returns the casefolded version of an expression?

Answer

Correct Answer: Fc

Note: This Question is unanswered, help us to find answer for this one

72. Which of the following Perl debugging commands is used for displaying all the commands that are longer than one character?

Answer

Correct Answer: H

Note: This Question is unanswered, help us to find answer for this one

73.

What will be the output of the following Perl command?

print v102.101.111;


Answer

Correct Answer:

feo 


Note: This Question is unanswered, help us to find answer for this one

74. In Perl 5.26.1, what is the default value of the debugging configurable option, windowSize?

Answer

Correct Answer: 10 lines

Note: This Question is unanswered, help us to find answer for this one

75.

What will be printed by the code below?

my $val = {};

print ref($val);

Answer

Correct Answer:

HASH


Note: This Question is unanswered, help us to find answer for this one

76.

What will be printed by the code below?

my $val = bless {}, 'MyClass';

print ref($val);

Answer

Correct Answer:

MyClass



Note: This Question is unanswered, help us to find answer for this one

77. The last and next statements are ideal for ............. that check for exceptional conditions?

Answer

Correct Answer: Loops

Note: This Question is unanswered, help us to find answer for this one

78. Autoloading of Perl functions is analogous to dynamic loading of compiled ____ functions?

Answer

Correct Answer: C

Note: This Question is unanswered, help us to find answer for this one

79. Which function returns true if the named key exists in a Hash?

Answer

Correct Answer: exists

Note: This Question is unanswered, help us to find answer for this one

80. Which are the configuration types in Spring?

Answer

Correct Answer: XML-Based , Annotation Based, JSON-Based

Note: This Question is unanswered, help us to find answer for this one

81. Which of the following are kinds of scalar values Perl supports?

Answer

Correct Answer: integers
floating
point numbers

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

82. Which function can be used to launch a child process to run a program in Perl?

Answer

Correct Answer: System

Note: This Question is unanswered, help us to find answer for this one

83. Which of the following is True about operator?

Answer

Correct Answer: Both of the above.

Note: This Question is unanswered, help us to find answer for this one

84. Which operator increases integer value?

Answer

Correct Answer: ++

Note: This Question is unanswered, help us to find answer for this one

85. Perl supports _____ operations on integer scalar values?

Answer

Correct Answer: base-2

Note: This Question is unanswered, help us to find answer for this one

86. Which statement is True of scalar context?

Answer

Correct Answer: Assignment to a scalar variable evaluates the right-hand side in a scalar context.

Note: This Question is unanswered, help us to find answer for this one

87. Which operator performs exponential (power) calculation on operators?

Answer

Correct Answer: **

Note: This Question is unanswered, help us to find answer for this one

88. What will be the value of $1 after execution of the following code?

Answer

Correct Answer: Perl

Note: This Question is unanswered, help us to find answer for this one

89. Which modifier can be used when matching in Perl to ignore case?

Answer

Correct Answer: v

Note: This Question is unanswered, help us to find answer for this one

90. Perl 5 defines _____ special subroutines that are executed at specific times?

Answer

Correct Answer: three

Note: This Question is unanswered, help us to find answer for this one

91. Which method pops off and returns the last value of the array?

Answer

Correct Answer: pop @ARRAY

Note: This Question is unanswered, help us to find answer for this one

92. Which of the following statements are correct about Hashes?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

93.

Which code is True of Variables-Hashes?


Answer

Correct Answer:

%hash = (


    key => “val”

    foo => $item,

   thingies => “some stuff”,

);

say $hash{key}; # “val” 


Note: This Question is unanswered, help us to find answer for this one

94.

What will be the size of the @fields array?

my $record = ':a:b:c:'; 

my @fields = split(':', $record, -1);

Answer

Correct Answer:

5


Note: This Question is unanswered, help us to find answer for this one

95. How can you work through an associative array in a specified order?

Answer

Correct Answer: If you need to access the elements of an associative array in a specified order, use keys and sort to sort the subscripts, and then retrieve the value associated with each element.

Note: This Question is unanswered, help us to find answer for this one

96. Which function opens a file in writing mode without truncating the file?