Perl Programming Language Quiz

Test your knowledge of Perl programming language syntax, operators, data structures, and built-in functions including regex patterns, array operations, hash manipulation, and string handling.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

shift (@array);

  1. splice (@array, 0, 1);
  2. splice (@array, @array-1, 1);
  3. splice (@array, scalar(@array), 0, @sublist);
  4. splice (@array, 0, 0, @sublist);
Question 2 Multiple Choice (Single Answer)

pop (@array);

  1. splice (@array, 0, 1);
  2. splice (@array, @array-1, 1);
  3. splice (@array, scalar(@array), 0, @sublist);
  4. splice (@array, 0, 0, @sublist);
Question 3 Multiple Choice (Single Answer)

@array = (1,2,3); $scalar = $array[3]; print “$scalar”;

  1. 3
  2. 0
  3. Error:Array value out of bound
  4. Null value
Question 4 Multiple Choice (Single Answer)

@array = (10,30,20); sort(@array); print @array;'

  1. 10 20 30
  2. 10 30 20
  3. 30 20 10
  4. 1 2 3
Question 5 Multiple Choice (Single Answer)

. '@array = (“cat”, “rat”, “mat”); chop(@array); print @array;'

  1. ca ra ma
  2. cat rat ma
  3. cat rat
  4. cat rat mat
Question 6 Multiple Choice (Single Answer)

$string = "Hello World"; substr($string,6)="Perl"; print $string;

  1. Hello Perl
  2. Hello Perl World
  3. Hello
  4. Perl World
Question 7 Multiple Choice (Single Answer)

if(143 lt 34) { print “If is true”; } else { print “If is false”; }

  1. If is true
  2. If is false
  3. Error
  4. No output
Question 8 Multiple Choice (Single Answer)

@array = (1,2,3,4,5) $scalar1, $scalar2 = @array; print “Scalar1 value is $scalar1”; print “Scalar2 value is $scalar2”;

  1. 1 2
  2. 4 5
  3. 4 4
  4. 4 0
Question 9 Multiple Choice (Single Answer)

$scalar = (10,20,30); print $scalar;

  1. 10
  2. 20
  3. 30
  4. 3
Question 10 Multiple Choice (Single Answer)

@array = (100, 80, 70); @sort_arr = sort(@array); print @sort_arr;'

  1. 70 80 100
  2. 100 80 70
  3. 100 70 80
  4. 1 2 3
Question 11 Multiple Choice (Single Answer)

What operator is used to check whether the file is empty or not

  1. -e'
  2. -s'
  3. -z'
  4. -x'
Question 12 Multiple Choice (Single Answer)

/d[^oO]g/ matches?

  1. dog
  2. dOg
  3. doOg
  4. dig
Question 13 Multiple Choice (Single Answer)

$input = “abdce”; $output = $input =~ tr/abc/123; print $input; print $output

  1. 12d3e 3
  2. 12d3e 5
  3. 12d3e 1
  4. Error
  5. 12d3e null string
Question 14 Multiple Choice (Single Answer)

The purpose of ?: in this is /(?: [a-z]+/ is?

  1. To enclose a subpattern in parenthesis without storing it in memory.
  2. To define a boundary condition
  3. To enclose a pattern within pattern
  4. None of the above
Question 15 Multiple Choice (Single Answer)

Which of the following is not a predefined subroutine?

  1. BEGIN
  2. END
  3. DEFAULT
  4. AUTOLOAD
  5. NONE OF THE ABOVE
Question 16 Multiple Choice (Single Answer)

Which is the best way to delete an element in an associative array?

  1. Delete
  2. Push
  3. Pop
  4. Shift
  5. Unshift
Question 17 Multiple Choice (Single Answer)

$string = “GoodWorld”; $string =~ s/o*/i/; The value of $string is?

  1. iGoodWorld
  2. GidWirld
  3. GidWorld
  4. Gioworld
  5. GoodWorld
Question 18 Multiple Choice (Single Answer)

$data = “Welcome Perl” =~ /(.*)/; print $data;

  1. 0
  2. 1
  3. Welcome
  4. Perl
  5. Welcome Perl
Question 19 Multiple Choice (Single Answer)

my %hash = ( 'hi' => {'hello' => 'all'}, 'bye' => {'later' => 'gone'} ); print $hash{'hi'};

  1. hello
  2. 0
  3. hello => all
  4. HASH(0x??????) where ?????? is a group of hex digits.
  5. error
Question 20 Multiple Choice (Single Answer)

my $val = ‘x’; print ref($val);

  1. scalar
  2. any decimal value
  3. empty value
  4. x