Ruby and Perl Programming Fundamentals

Test your knowledge of Ruby and Perl programming concepts including loops, arrays, hashes, syntax, and string operations.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

The printf format "%6.2f" displays a number

  1. At least six columns wide in total, with two figures after the decimal place
  2. Exactly six digits before the decimal place, and two digits after
  3. At least six digits before the decimal place, and two digits after
  4. Exactly six columns wide in total, with two figures after the decimal place
Question 2 Multiple Choice (Single Answer)

In Perl, which of the following are file handles?

  1. stdquit
  2. stdend
  3. stdin
  4. stdout
  5. c&d
Question 3 Multiple Choice (Single Answer)

$val = 'a\b\n';print $val;What gets printed?

  1. ab(newline)
  2. a\b(newline)
  3. a\b\n
  4. a\b(newline)
  5. a\b\n
Question 4 Multiple Choice (Single Answer)

my $txt = 'I am learning Perl'; $txt =~ /(\w+)$/; What is value of $txt?

  1. Perl
  2. I
  3. I am learning Perl
  4. undef
  5. empty string
Question 5 Multiple Choice (Single Answer)

Which of the following is NOT a comment line in a Perl program?

  1. # This is a comment
  2. #! This is a comment
  3. # Comment Line #
  4. ##########################################################
Question 6 Multiple Choice (Single Answer)

Which of the following is used in perl?

  1. else if
  2. elseif
  3. elsif
  4. elif
Question 7 Multiple Choice (Single Answer)

Which of the above is valid variable name?

  1. $_4x
  2. $10thLine
  3. $line.No
  4. count
  5. $lineNo!
Question 8 Multiple Choice (Single Answer)

which one of the below is correct with respect to string repeatation a) print "TEST" X 10; b) print "TEST" x 10; c) print 10 X "TEST"; d) print 10 x "TEST";

  1. a
  2. b
  3. c
  4. d
  5. b and d
Question 9 Multiple Choice (Single Answer)

What will be the value of $keys? my %hash; $hash{undef} = undef; $hash{''} = ''; my $keys = keys(%hash);

  1. undef
  2. 0
  3. 1
  4. 2
  5. the code is ill-formed
Question 10 Multiple Choice (Single Answer)

which is among the following is not a loop a) For b) foreach c)map d) until e) switch

  1. a
  2. b
  3. c
  4. d
  5. e
Question 11 Multiple Choice (Multiple Answers)

“name” is an array.Which of the following are correct way to find size of a ruby array? Select all that apply.

  1. name.length
  2. name.size
  3. size(name)
  4. length(name)
Question 12 True/False

The correct way to find index of an array element.days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ] is days.index(“Saturday”).

  1. True
  2. False
Question 13 True/False

i = 0 10.times do i += 1 puts i End The output will be => 1 2 3 4 5 6 7 8 9 10

  1. True
  2. False
Question 14 True/False

0.upto(10) { |i| puts I} Output will be=> 1 2 3 4 5 6 7 8 9 10

  1. True
  2. False
Question 15 True/False

0.upto(10) { |i| puts i} Output will be=> 0 1 2 3 4 5 6 7 8 9 10

  1. True
  2. False
Question 16 True/False

my_array = ["alpha", "beta", "gamma"] puts my_array.collect do |word| word.capitalize End==> output? alpha beta gamma

  1. True
  2. False
Question 17 True/False

my_array = ["alpha", "beta", "gamma"] puts my_array.collect { |word| word.capitalize } Output => Alpha Beta Gamma

  1. True
  2. False
Question 18 True/False

for ss in 1...10 print ss, " Hello\n";end => Find output? 1 Hello 2 Hello 3 Hello 4 Hello 5 Hello 6 Hello 7 Hello 8 Hello 9 Hello

  1. True
  2. False
Question 19 True/False

ss = 5 while ss > 0 puts ss ss -= 2 if ss == 1 ss += 5 end end Output=> 5 3 6 4 2

  1. True
  2. False
Question 20 True/False

ss = 5 while ss > 0 puts ss ss -= 2 if ss == 1 ss += 5 end end The output will be 5 3 6 4 2 7

  1. True
  2. False