PERL quiz and interview questions

Comprehensive PERL quiz and questions from basic to advanced level that help you to review your PERL knowledge and become the master of PERL. Please read the following question carefully and select the correct anwser, you have to make your choice before going to the next question.

Recent added questions

  • How can information be put into hashes?

    Answer:

    When a hash value is referenced, it is not created. It is only created once a value is assigned to it. The contents of a hash have no literal representation. In case the hash is to be filled at once the unwinding of the hash must be done. The unwinding of hash means the key value pairs in hash can be created using a list, they can be converted from that as well. In this conversion process the even numbered items are placed on the right and are known as values. The items placed on the left are odd numbered and are stored as keys. The hash has no defined internal ordering and hence the user should not rely on any particular ordering.

    Example of creating hash:

    %birthdate = ( Ram => "01-01-1985",
    Vinod => "22-12-1983",
    Sahil => "13-03-1989",
    Sony => "11-09-1991");

     

  • Which of the following will be matched by this code?

    my $pattern = '.*';
    $str =~ /(\Q$pattern\E)/;
  • Which of the following erases all entries in the %h hash?

  • Which of the following is the correct way of sorting an array of integers in ascending order?

  • What gets printed?

    my $var = 1;
    $main::var = 2;
    if ($var == $main::var) {
      print 'true';
    } else {
      print 'false';
    }
  • How many key-value pairs will the hash contain?

    my %hash = (
      [1, 2] => 1,
      [1, 2] => 2
    );
  • Which messages will be printed?

    package Animal;
    sub AUTOLOAD {}                                   
    sub new { bless {}, shift }
    package Dog;
    use base 'Animal';
    sub run {}
    package main;
    my $obj = Dog->new();
    if ($obj->can('run')) {
        print "can run\n"  
    }
    if ($obj->can('bark')) {
        print "can bark\n"  
    }
  • What gets printed?

    package A;
    sub NEW { bless {}, shift }
    sub AUTOLOAD { print ref(shift) }
    package main;
    my $obj = NEW A;
    $obj->foo();

View all PERL quiz questions

© 2017 QuizBucket.org