Thứ Tư, 8 tháng 8, 2012

Trắc nghiệm kiến thức ngôn ngữ PERL

Trong bài này, chúng ta sẽ trắc nghiệm một số kiến thức cơ bản về ngôn ngữ PERL.

Câu 1. When you're pattern matching, you describe the pattern using:

1. A string in double quotes
2. A MySQL select statement
3. A regular expression
4. A template

Câu 2. Perl is:

1. A type of interactive web page
2. A programming language
3. An application program
4. A relational database

Câu 3. 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

Câu 4. The statement open (FH,"abc.txt"); 
 
1. opens the file abc.txt for overwriting
2. opens the file abc.txt for reading
3. contains an error, so won't compile
4. opens the file abc.txt for appending

Câu 5. When you create a variable, you may assume it starts off containing:

1. 1
2. You may not make any assumption
3. The boolean value "false"
4. A null string (or 0 arithmetically)

Câu 6. Which brackets do you use to change the order of precedence of operations?

1. Curly braces
2. Square brackets
3. Round brackets
4. You don't use brackets in Perl - you write in RPN (Reverse Polish Notation)

Câu 7. Which of the following tests if the string held in $qn includes the word "perl"?

1. if ($qn =~ /perl/) .....
2. if ($qn == "perl") ....
3. if ($qn = "perl") .....
4. if ($qn eq "perl") .....

Câu  8. Which of these is NOT available for Perl: \

1. Perl, legally, for free
2. Individual and site licenses
3. Full documentation of the language which you can print out yourself
4. A Carribean cruise in 2006 on which you can meet some of the Perl gurus.

Câu 9. Perl was first released in:

1. 1978
2. 1998
3. Perl hasn't yet been released
4. 1988

Câu 10. Which of the following is NOT a comment line in a Perl program?

1. # This is a comment
2. #/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/
3. ##########################################################
4. //////////////////////////////////////////////////////////

Câu 11. What is a file handle used for?

1. Reading binary data from a file into a scalar variable
2. Finding where a file is on the disc
3. Accessing a disc file or other input/output stream
4. Deleting, moving or renaming a file

Câu 12. The "%" operator returns:

1. The larger of two numbers e.g. 200 % 20 would return 200
2. A percentage of a number e.g. 200 % 20 would return 40
3. The remainder when one number is divided by another
4. The remainder when one number is divided by another e.g. 18 % 7 would return 5

Câu 13. What is Perl?

1. Practical Extraction and Report Language
2. Practice for Exclusive and Report Language
3. Practical Extraction and Report Learning
4. Practical Exclusive and Report Language

Câu 14. Which of the following is used in perl?

1. else if
2. elseif
3. elsif
4. elif

Câu 15. The $_ variable

1. holds the last pattern matched.
2. holds the output field separator.
3. identifies the current command line argument.
4. none of the above is correct.

Câu 16. The getdir command

1. Reads a single file name from an open directory handle.
2. Reads the rest of the file names from an open directory handle.
3. Only works after anopendir command.
4. Is not a perl command.

Câu 17. The value of the expression $yards += 10

1. is 10.
2. is true.
3. cannot be determined from the information given.
4. relies on which command line arguments were used.

Câu 18. $x = @y[2 .. 4]

1. assigns$x the third, fourth and fifth elements of the y array concatenated together.
2. assigns$y[4] to $x.
3. assigns$y[2] to $x.
4. assigns 3 to$x.

Câu 19. Which of the following commands will turn a scalar ($str)into an array of characters?

1. @a = split($str).
2. @a = split(/\s/, $str).
3. This task can be done in Perl but none of the above commands do it.
4. @a = split(/./, $str).

Câu 20. <ARGV>

1. more than one of the above is correct.
2. identifies any command line arguments starting with a-.
3. will read the standard input if no arguments are listed on the command line.
4. can be used to read each line in every file name listed on the command line.

Câu 21. How do you perform a forward declaration of a subroutine performed?

1. forward sub name;
2. sub name;
3. forward name;
4. sub name {};
5. sub {};

Câu 22. Sample Code 
 
Code: INSERT INTO names VALUES ('John') 
 
How do you use the DBI module to execute the above SQL statement? Assume $dbh is the return value from DBI->connect.

1. my $statement = $dbh->execute("INSERT INTO names VALUES ('John')");
2. my $statement = $dbh->sql("INSERT INTO names VALUES ('John')"); $statement->execute;
3. my $statement = $dbh->prepare("INSERT INTO names VALUES ('John')"); $statement->execute;
4. my $statement = $dbh->run("INSERT INTO names VALUES ('John')");
5. my $statement = $dbh->insert("INSERT INTO names VALUES ('John')"); $statement->finish;

Câu 23. Which regular expression deletes all tags specified as text enclosed by "<" and ">" from a document stored in a string, but deletes nothing else.

1. $string =~ s/<*&>//g;
2. $string =~ s/<\S*>//g;
3. $string =~ s/<\s*>//g;
4. $string =~ s/<.*?>//g;
5. $string =~ s/<.*>//g;

Câu 24. Which one of the following completely defines scalars?

1. A number, an array, or a associative array
2. A single string, number, or reference
3. A string, a lexical array, or a numeric value
4. A pointer, a stack, or a heap
5. An int, float, double, or char

Câu 25. Sample Code 
 
Code: @values = ( "value1", "value2", ("value3", "value4") ); 
 
How does Perl store the nested list shown above?

1. The list is stored as a hierarchical list.
2. The list is stored as a hash with the offsets as keys to the hash.
3. The list is flattened by removing all internal bracketing.
4. The list stores two values, "value1" and "value2", plus a pointer to the internal list.
5. The list stores two values, "value1" and "value2", plus two pointers to "value3" and "value4."

Câu 26. Sample Code 
 
Code: printSorted(\@list,dir => 'asc', type => 'numerical'); 
 
Many functions in perl take option lists such as the ones in the above code sample. 
 
Given the information shown above, what does the line in the printSorted subroutine that retrieves the parameters probably look like?

1. my (@data,$options) = @_;
2. my ($data,%options) = @_;
3. my ($data,$option1,$option2) = @_;
4. my ($data,$options) = @_;
5. my (@data,@options) = @_;

Câu 27. Which one of the following regexes matches between 1 to 4 ab's followed by a tab and an integer number?

1. (ab)+{4}\t\d*
2. ab[ababab]\t[0-9]
3. {ab,4}\t\d+
4. (ab)?[1-4]\t[0-9]*
5. (ab){1,4}\t\d+

Câu 28. Sample Code 
 
Code 1: Code: my @lines = grep /^hi/, @allLines; 
Code 2: Code: my @lines = (); foreach (@allLines) { push (@lines,$_) if (/^hi/); } 
 
What is the difference between the two snippets (Code 1 and Code 2) above?

1. In code 1, the operation occurs in one command; code 2 iterates each element in the array for matches.
2. In code 1, the elements of @lines are the indexes in @allLines, in which matches were found.
3. In code 1, the elements of "@lines" begin with the index in "@allLines", in which the match was found.
4. In code 2, no matches are found.
5. In code 1, "@lines" may not necessarily be in the same order; the original lines appear in "@allLines".

Câu 29. Which conditional statement is equivalent to "if (!<condition>)"?

1. unless (<condition>)
2. failure (<condition>)
3. fails (<condition>)
4. ifn (<condition>)
5. require (<condition>)

Câu 30. Problem You need to check to see what version of Perl a module you have written is running. You know that Perl versions earlier than 5.005 do not work properly with your module. Given the problem shown above, how do you check that the version of Perl is new enough?

1. Using "$|>=5.005"
2. Using "$]>=5.005"
3. Using "%INC{VERSION}>=5.005"
4. Using "$PERLVER>=5.005"
5. Using "gt;=5.005"
 
Editor: Vương Lan Kiều
Source: http://baomathethong.blogspot.com/
Copyrighted Content: Ezdia.com, Academictutorials.com

Không có nhận xét nào:

Đăng nhận xét