1. Which statement is wrong:
A. $_= ‘hello world’;
B. $a=’hello world’;
C. my $b,$a=’hello world’;
D. my ($a,$b)=(0,’hello world’);
Answer:
Item C: $b is empty and $a is ‘hello world’
All of items is correct in program syntax, and can run.
2. The expression should be ( ), then the following code can run correctly:
$a=0;$b=55;
while (expression)
{
$a+=2;
}
print "$a\n";
A. $a = $b
B. $a*$a <= $b
C. $a != $b
D. $b == 0
Answer: B
3. @array is an array variable, what is output of “print @array;” :
A. Each element of this array
B. The size of this array
C. The first element of this array
D. Nothing
Answer: A
4. “$a = @array;”, what is value of $a:
A. The first element’s value of this array
B. The size of this array
C. This line code is wrong
D. N/A
Answer:B
5. Which code snippet can print all elements in %abcd:
A. foreach $Var (keys %abcd)
{
print “$Var \n”;
}
B. for ($I=0;$I<%abcd;$I++)
{
print “$%abcd{$I} \n”;
}
C. while ($Var (keys %abcd))
{
print “$Var \n”;
}
D. print join(‘\n’,%abcd);
Answer:A
Advance:
6. After execute following code snippet, what is value of $count:
$Str=’hello world!’;
$count=0;
while ($Str=~m/(\w+)/g)
{
$count++;
}
A. 1
B. 2
C. 3
D. 12
Answer: B (match twice)
7. What is the result of $string?
$string = “This string contains the number 25.11.”;
$string =~ /-?(\d+)\.?(\d+)/;
A. 25.
B. .11
C. 25.11
D. 25.11.
Answer:D
8. What is meaning of following code snippet?
open(MYFILE,"temp.txt");
while () {
while ( /(\w)/g ) {
$seen{$1}++;
}
}
foreach $word(keys %seen)
{
print "$seen{$word} $word\n";
}
close(MYFILE);
A. Delete all words in temp.txt
B. Calculate the frequency of each word in temp.txt
C. Wrong code
D. Calculate the sum of words in temp.txt
Answer: $1 is first variable of group match of perl, it match a char here.
9. In following code, expression#1 ( ) let $point get the reference of @ARGV, expression#1 should be:
#!/usr/contrib/bin/perl -w
expression#1
print "ARGV = ", join(",", expression#2), "\n";
A. my $point=@ARGV;
B. my $point={@ARGV};
C. my $point=ARGV;
D. my $point=\@ARGV;
Answer: D
10. The expression#2 should be ( ):
A. @$point
B. $point
C. @point
D. \@point
Answer: A
阅读(9145) | 评论(0) | 转发(1) |