Ruby and Perl Programming Fundamentals
Test your knowledge of Ruby and Perl programming concepts including loops, arrays, hashes, syntax, and string operations.
Questions
The printf format "%6.2f" displays a number
- At least six columns wide in total, with two figures after the decimal place
- Exactly six digits before the decimal place, and two digits after
- At least six digits before the decimal place, and two digits after
- Exactly six columns wide in total, with two figures after the decimal place
In Perl, which of the following are file handles?
- stdquit
- stdend
- stdin
- stdout
- c&d
$val = 'a\b\n';print $val;What gets printed?
- ab(newline)
- a\b(newline)
- a\b\n
- a\b(newline)
- a\b\n
my $txt = 'I am learning Perl'; $txt =~ /(\w+)$/; What is value of $txt?
- Perl
- I
- I am learning Perl
- undef
- empty string
Which of the following is NOT a comment line in a Perl program?
- # This is a comment
- #! This is a comment
- # Comment Line #
- ##########################################################
Which of the following is used in perl?
- else if
- elseif
- elsif
- elif
Which of the above is valid variable name?
- $_4x
- $10thLine
- $line.No
- count
- $lineNo!
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";
- a
- b
- c
- d
- b and d
What will be the value of $keys? my %hash; $hash{undef} = undef; $hash{''} = ''; my $keys = keys(%hash);
- undef
- 0
- 1
- 2
- the code is ill-formed
which is among the following is not a loop a) For b) foreach c)map d) until e) switch
- a
- b
- c
- d
- e
“name” is an array.Which of the following are correct way to find size of a ruby array? Select all that apply.
- name.length
- name.size
- size(name)
- length(name)
The correct way to find index of an array element.days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ] is days.index(“Saturday”).
- 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
- True
- False
0.upto(10) { |i| puts I} Output will be=> 1 2 3 4 5 6 7 8 9 10
- True
- False
0.upto(10) { |i| puts i} Output will be=> 0 1 2 3 4 5 6 7 8 9 10
- True
- False
my_array = ["alpha", "beta", "gamma"] puts my_array.collect do |word| word.capitalize End==> output? alpha beta gamma
- True
- False
my_array = ["alpha", "beta", "gamma"] puts my_array.collect { |word| word.capitalize } Output => Alpha Beta Gamma
- 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
- True
- False
ss = 5 while ss > 0 puts ss ss -= 2 if ss == 1 ss += 5 end end Output=> 5 3 6 4 2
- 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
- True
- False