Module 2: PERL
Assignment Level 0: No. 1
1. Which one of the following is NOT a valid Perl variable?
(a) $a123 (b) $a_123 (c) $a-123 (d) @a_123
2. Perl is a very useful language because (select all applicable):
(a) it is an interpretive language
(b) it has only three types of variables
(c) it has powerful string processing capabilities
(d) it is very similar to C
3. The following sequence of Perl statements are expected to calculate a value
500/10, i.e. 50. Is this sequence correct? If not, correct it, if yes, explain why
it is OK:
---------------------------------------------------
$value = "500";
$v = $value/10;
print "$v\n";
---------------------------------------------------
4. What will be the output of the following sequence of statements?
---------------------------------------------------
$name = "Himanshu";
print ’$name\n’;
---------------------------------------------------
5. Which of the following "shebang" is/are NOT correct?
---------------------------------------------------
#! /usr/bin/perl
# !/usr/bin/perl
#!/usr /bin/perl
#!/usr/bin/perl
---------------------------------------------------
6. Is the following little program correct? If not correct it:
---------------------------------------------------
#!/usr/bin/perl
Module 2: PERL
{print "Hello, World!\n"}
---------------------------------------------------
7. What is wrong with the following array definition:
---------------------------------------------------
@myarray = [ 1, 2, 3, 4, 5];
---------------------------------------------------
8. What output is printed for the following code segment?
---------------------------------------------------
@a = (11, 22, 33, 44, 55);
print "$a[0] $a[4]\n";
---------------------------------------------------
9. What is the output from the following program, if KB input is respectively
50, 8, 35 and 250?
---------------------------------------------------
#!/usr/bin/perl
$price = <STDIN>;
if ($price > 100) {print "expensive"}
elsif ($price < 10) {print "bargain!"}
elsif ($price < 40) {print "cheap"}
else {print "standard"}
print "\n";
---------------------------------------------------
10. Write a perl program to read two text files f1.txt and f2.txt and output a file
f3.txt, which contains lines alternately from the two input files. Assume that
the two input files have exactly same number of lines.