0

PERL Programming - 1

Description: PERL Programming
Number of Questions: 15
Created by:
Tags: Computer Programming
Attempted 0/15 Correct 0 Score 0

Which of the following piece of code print the text covered by double quotes.

For Example: "Sun rises in the East"

  1. print Sun rises in the East

  2. print 'Sun rises in the East'

  3. print ' "Sun rises in the East" '

  4. print " 'Sun rises in the East ' "

  5. display "Sun rises in the East"


Correct Option: C
Explanation:

Yes, It prints the text surrounded by the double quotes. "Sun rises in the East"

Match the following:

 
A. Scalar I. $
B. Array II. %
C. Associated Array III. @
IV. *
  1. A - II, B - IV, C - I

  2. A - I, B - III, C - II

  3. A - II, B - IV, C - III

  4. A - I, B - II, C - III

  5. No prefix is required for the variable declaration in PERL.


Correct Option: B
Explanation:

Yes, Correct.

Choose the wrong one from the following SCALAR variable declarations

  1. $First_Name = "Kumar"

  2. $Salary = 1234.56

  3. $My.Country =" INDIA"

  4. $Player = Sachin

  5. $Country_code = 91


Correct Option: C
Explanation:

It is wrong. Compilation Error. Dot or period is not allowed in between the variable name.

Find the correct syntax from the following

  1. @ages = (35, 56, 29);
    @names = ("Pavan", "Chakri", "Kumar"); print "$ages[0] = ages[2]n";

    It displays $ages[0] = 29

  2. @array = qw/This is also an array/; print @array; print $array[2];

    It displays is

  3. @Months = qw/Jan Feb Mar Apr May Jun/ ;

    print "$Months[-6]n";

    It gives compilation error

  4. @My_array = (ab .. ag)

    print @My_array displays

    ab ac ad ae af ag

  5. None of the above


Correct Option: E
Explanation:

Yes, None of the above options are correct

Which of the following syntax will return the size of the array @My_array @My_array = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

  1. @My_array

  2. print @My_array

  3. print $My_array

  4. $size = @My_array; print $size;

  5. $size1 = $#My_array; print $size1;


Correct Option: D
Explanation:

Yes, scalar variable will get the size of array @My_array

Find the wrong array declaration from the following.

  1. @array1 = (5, 10, 15, 20, 25.45);

  2. @array1 = (5, 10, 15, 20, 25); @array2 = (1, 2, 3, 4, @array1);

  3. @My_array = 10

  4. @My_array = (Delhi, Calcutta, Mumbai, Bangalore, 5, 10, 15, 20)

  5. @array1 = 1; @array2 = 10; @My_array = (@array1 .. @array2);


Correct Option: E
Explanation:

It does not work. To get a range of values. you might have declared the 1 and 10 as SCALAR datatypes. The follwing declaration will work perfectly.

$var1 = 1; $var2 = 10; @My_array = ($var1 .. $var2);

@alpha = (a..z); print "Before splicing - @alphan";

splice (@alpha, 5, 3, "af".."ah"); print "After splicing - @alphan";

This code produces the following result Before splicing - a b c d e f g h i j k l m n o p q r s t u v w x y z After splicing - a b c d e af ag ah i j k l m n o p q r s t u v w x y z

Which of the following statement is correct about the above piece of code. (Multiple answers mighe be correct)

  1. splice( ) function has the first argument as the array name.

  2. splice( ) function has the second argument as the OFFSET. Starting position in the array. Here the offset is 5

  3. splice() function has the third argument as the LENGTH. The function replaces the elements starting from the OFFSET and count the number of elements mentioned in the LENGTH parameter. Here 3 is the length. So the elements f g h are picked for replacement

  4. splice() function has the fourth argument as the LIST of elements to replace with. The function replaces the elements starting from the OFFSET and count the number of elements mentioned in the LENGTH parameter with the LIST.

  5. All the above are correct.


Correct Option: E
Explanation:

Yes, All the statements are correct about the above piece of code

Find the wrong Array declaration

  1. @My_array = (2, 4, 6, 8, 10)

  2. @My_array = (1, 5, 8.9, 45.90)

  3. @My_array = (1 to 10)

  4. @My_array = (1 .. 10)

  5. @My_array = (100, 1 .. 10)


Correct Option: C
Explanation:

Keyword to does not work for defining the range of numbers.

Consider @Countries = ("India", "Denmark", "Russia", "Germany", "Japan", "Ireland")

Which of the following statement is correct about the Array operations? (Multiple answers might be correct)

  1. shift(@Countries) will remove country "India" from the beginning of the array @Countries

    Now @Countries looks like @Countries = ("Denmark", "Russia", "Germany", "Japan", "Ireland")

  2. shift(@Countries) will remove country "Ireland" from the end of the array @Countries

    Now @Countries looks like @Countries = ("India", "Denmark", "Russia", "Germany", "Japan")

  3. unshift(@Countries, "Canada") will add country "Canada" at the end of the array @Countries

    Now @Countries looks like @Countries = ("India", "Denmark", "Russia", "Germany", "Japan", "Canada")

  4. unshift(@Countries, "Canada") will add country "Canada" at the front of the array @Countries.

    Now @Countries looks like @Countries = ("Canada", "India", "Denmark", "Russia", "Germany", "Japan")

  5. None of the above are correct


Correct Option: A
Explanation:

Yes, unshift prepends the elements at the front of the array and returns the length of the array Yes, shift function removes the first element of the array and shifts all the other elements to 1 position.

$TCS_Office = "TATA CONSULTANCY SERVICES LIMITED, MADHAPUR".

Which of the following piece of code will convert the above string into array of elements and assign to @TCS_Off_Addr @TCS_Off_Addr = ("TATA", "CONSULTANCY", "SERVICES", "LIMITED,", "MADHAPUR");

  1. @TCS_Off_Addr = split(' ', $TCS_Office);

  2. @TCS_Off_Addr = split / /, $TCS_Office;

  3. @TCS_Off_Addr = split($TCS_Office, ' ');

  4. Both Option 1 and Option 2 are correct

  5. All options 1, 2 and 3 are correct.


Correct Option: D
Explanation:

Yes, Both Options 1 & 2 are correct.

Which of the following does not print the size of the array @My_array = (1..10);

  1. print scalar @My_array

  2. $my_arr_size = @My_array print $my_arr_size

  3. print $#My_array

  4. print 0+@My_array

  5. print $#My_array + 1


Correct Option: C
Explanation:

Yes, It returns the maximum index of the array, i.e. one less than the size of the array.

Pick the wrong piece of code regarding the transformation of text into array.

  1. $str = "PERL is one of the popular programing languages"; @words = split(' ', $str);

  2. $str = "PERL is one of the popular programing languages"; @words = split('', $str);

  3. $str = "PERL is one of the popular programing languages"; @words = split(' ', $str, 3);

  4. Option 1 and Option 3 are correct

  5. All 3 codes are correct and gives different results


Correct Option: E
Explanation:

Yes, All are different and valid codes.

Consider the Array @Countries = ("India", "Denmark", "Russia", "Germany", "Japan", "Ireland")

Which of the following statement is correct about the Array operations?

  1. push(@Countries, "Canada") will add new country "Canada" at the beginning of the array @Countries

    Now @Country gives @Countries = ("Canada", "India", "Denmark", "Russia", "Germany", "Japan", "Ireland")

  2. push(@Countries, "Canada") will add new country "Canada" at the end of the array @Countries

    Now @Countries gives @Countries = ("India", "Denmark", "Russia", "Germany", "Japan", "Ireland", "Canada")

  3. pop(@Countries, "India") will remove country "India" from the array @Countries

    Now @Countries looks like @Countries = ("Denmark", "Russia", "Germany", "Japan", "Ireland")

  4. pop(@Countries, "Ireland") will remove the country "Ireland" from the array @Countries

    Now @Countries looks like @Countries = ("India", "Denmark", "Russia", "Germany", "Japan")

  5. pop(@Countries) will remove the country "Ireland" last element of the array @Countries

    Now @Countries looks like @Countries = ("India", "Denmark", "Russia", "Germany", "Japan")


Correct Option: B
Explanation:

Yes, Push function on array will add element at the end of the array Yes, pop function removes one element at the end of the array. It has only one argument, i.e., Array Name..

Which of the following is correct about Hashes in PERL ?

  1. Hash is a set of Key Value pair and denoted by a symbol %

  2. %Scores_Of = ('Sachin', 90, 'Dravid', 75, 'Sehwag', 51, 'Kumble', 8);

  3. %Scores_Of = ('Sachin' => 90, 'Dravid' => 75, 'Sehwag' => 51, 'Kumble' => 8);

  4. %Scores_Of = (-Sachin => 90, -Dravid => 75, -Sehwag => 51, -Kumble => 8);

  5. All the above are correct


Correct Option: E
Explanation:

Yes, All are correct about Hashes in PERL.

Pick wrong piece of code for printing the Hashes in PERL Consider the hash %My_Portfolio = ('DFHL', 100, 'ITC', 250, 'ASHOKLEY', 500, 'AXISBANK', 150);

  1. print "$_n" for keys %My_Portfolio;

  2. print scalar keys %My_Portfolio;

  3. print "%My_Portfolio";

  4. @Stocks = keys %My_Portfolio; print "$Stocks[1]n";

  5. @Quantity = values %My_Portfolio; print "$Quantity[2]n";


Correct Option: C
Explanation:

Here is the trap. It takes %My_Portfolio as a string. Does not recognize as a Hash.

- Hide questions