PERL quiz questions

PERL interview questions

  • 1.

    What elements will the @a array consist of?

    $_ = ' a b c ';
    
    my @a = split();
    1. ' ', 'a', ' ', 'b', ' ', 'c', ' '

    2. '', 'a', 'b', 'c', ''

    3. undef, 'a', 'b', 'c', undef

    4. 'a', 'b', 'c'

    5. ' ', 'a', 'b', 'c'

    Answer
  • 2.

    The following operator will collapse all duplicate spaces into single spaces in the string $str

    $str =~ s/\s+/ /;
    1. true

    2. false

    Answer
  • 3.

    What will be the output of the code below?

    package A;
    
    sub new {
        my $class = shift;
        return bless {}, $class;
    }
    
     
    package B;
    use base 'A';
    
    sub foo {
        return 'blah';
    }
    
    
    package main;
    
    my $obj = B->new();
    
    print $obj->foo(), "\n";
    1. blah

    2. Can't locate object method "new" via package "B"

    Answer
  • 4.

    What will be the size of the @fields array

    my $record = ':a:b:c:'; 
    
    my @fields = split(':', $record, -1);
    1. 0

    2. 1

    3. 3

    4. 5

    Answer
  • 5.

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

    my $txt = 'I am learning Perl';
    
    $txt =~ /(.*)\s/;
    1. none

    2. I am learning Perl

    3. I am learning

    4. I

    5. learning

    Answer
  • 6.

    What part of the string will be assigned to $match in the following code

    my $txt = 'I am learning Perl';
    
    my ($match) = $txt =~ /\s(.*)\s/;
    1. am learning

    2. I am learning Perl

    3. learning

    4. am

    5. none

    Answer
  • 7.

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

    my $txt = 'I am learning Perl';                    
    
    $txt =~ /(\w+)$/;
    1. Perl

    2. I

    3. I am learning Perl

    4. undef

    5. empty string

    Answer
  • 8.

    What will be printed by the code below?

    my $val = bless {}, 'MyClass';
    
    print ref($val);
    1. true

    2. HASH

    3. object reference

    4. 1

    5. MyClass

    Answer
  • 9.

    What will be printed by the code below?

    my @a = (0, 1, 2);
    my ($b) = @a;
    
    print $b;
    1. 0

    2. 1

    3. 2

    4. 3

    5. 0 1 2

    Answer
  • 10.

    What will be printed by the code below?

    my @a = (0, 1, 2);
    my $b = @a;
    
    print $b;
    1. 0

    2. 1

    3. 2

    4. 3

    5. 0 1 2

    Answer
  • 11.

    What will be printed by the code below?

    my $val = {};
    
    print ref($val);
    1. empty value

    2. ARRAY

    3. HASH

    4. SCALAR

    5. true

    Answer
  • 12.

    What will be printed by the code below?

    my $val = 'x';
    
    print ref($val);
    1. SCALAR

    2. empty value

    3. STRING

    4. "not a reference"

    Answer

© 2017 QuizBucket.org