24 hours of Perl programming course questions

Source: Internet
Author: User
Tags perl interpreter scalar

24 hours of Perl programming course questions
I. multiple choice questions
1. Which of the following strings is incorrectly defined ()
(1) 'Thank you'
(2 )""
(3) "A" friend "of yours"
(4) "A/" friend/"of yours"
2. Which of the following statements is incorrect ()
(1) $ _ = 'Hello world ';
(2) $ A = 'Hello world ';
(3) My $ B, $ A = 'Hello world ';
(4) My ($ A, $ B) = (0, 'Hello World ');
3. To make the following program run properly, the while expression should be selected ().
$ A = 0; $ B = 55;
While (expression)
{
$ A + = 2;
}
Print "$ A/N ";
(1) $ A = $ B
(2) $ A * $ A <= $ B
(3) $! = $ B
(4) $ B = 0
4. in Perl and other programming languages, data is composed ().
(1) variables.
(2) operator.
(3) The value of the variable.
(4) The value of the operator.
5. @ array is an array variable. The print @ array statement outputs :()
(1) elements of the array.
(2) The size of the array.
(3) The first element of the array.
(4) Nothing is output.
6. After the statement $ A = @ array; is executed, the value of $ A is ().
(1) The value of the first element of array @ array.
(2) Size of array @ array.
(3) the syntax of this statement is incorrect.
(4) not defined.
7. Use recursive subprograms to obtain the power of 45 to the third. The if expression should be ()
Sub power
{
($ M, $ n) = @_;
$ N> = 1 | die 'error! ';
Return ($ m) if (expression );
Return ($ M * power ($ M, $ N-1 ));
}
Print power (45, 3 );
(1) $ n = 1
(2) $ n <0
(3) $ n> = 1
(4) $ n! = 0
8. To accept two arrays as parameters in a subroutine ()
(1) The subroutine uses a two-dimensional array as the form parameter.
(2) The subroutine uses two arrays as the form parameters.
(3) The subroutine uses two references as the form parameters.
(4) subprograms cannot be implemented.
9. The following program expression 1 will create a reference $ point for the array @ argv containing command line parameters. The expression 1 should be ()
#! /Usr/contrib/bin/perl-W
1: expression 1
2: Print "argv =", join (",", expression 2), "/N ";
(1) My $ point = @ argv;
(2) My $ point ={@ argv };
(3) My $ point = argv;
(4) My $ point = // @ argv;
10. The above program expression should be ()
(1) @ $ point
(2) $ point
(3) @ point
(4) // @ point
11. Which of the following strings can match the pattern/[^/d ^? ()
(1)-10
(2) 200
(3) ABC123
(4) # % @
12. Which of the following sections can display all elements in the hash structure % ABCD? ()
(1) foreach $ VAR (Keys % ABCD)
{
Print "$ var/N ";
}
(2) For ($ I = 0; $ I <% ABCD; $ I ++)
{
Print "$ % ABCD {$ I}/N ";
}
(3) While ($ VAR (Keys % ABCD ))
{
Print "$ var/N ";
}
(4) print join ('/N', % ABCD );
13. After the following program is executed, the value of the variable $ count is ()
$ STR = 'Hello world! ';
$ COUNT = 0;
While ($ STR = ~ M/(/W +)/g)
{
$ Count ++;
}
(1) 1
(2) 2
(3) 3
(4) 12
14. The role of the following programs is ()
Open (myfile, "temp.txt ");
While (<myfile> ){
While (/W)/g ){
$ Seen {$1} ++;
}
}
Foreach $ word (Keys % seen)
{
Print "$ seen {$ word} $ word/N ";
}
Close (myfile );
(1 delete all word characters in the temp.txt file.
(2) temptemptemptemp temptemptemptemptemptemptemptemptemptemp.
(3) Incorrect program.
(4)count the total number of word characters in temp.txt.
15. If a value named my is encoded in the URL submitted to temp. cgi in post mode, such
<Form action = "lindi.com/temp.cgi? My = 20 "method =" Post "> This URL also has a domain with the same name in the form, for example, <input type = "text" name = "my" value = "1">. In temp. cgi, the statement $ Var = param ('my'); after execution, the value of the variable $ VaR is ()
(1) 2
(2) UNDEF
(3) 20
(4) 1
(Answer)
Ii. Answer questions
1. Print 'No! 'If ($! = 'Hello'); after execution, no is displayed when the value of $ A is not equal to 'Hello! ()
2. The operator (+) can join two strings. ()
3. The "my" operator works the same as the "local" operator. ()
4. The statement print 'Hello "world" '; is correct. ()
5. logical operators (|) and (or) have the same priority. ()
6. Use the statement my myfile; to define a variable of the file handle type. ()
7. The regular expression m'/u/jqpublic/perl/Lindi 'is equivalent to // U // jqpublic // Perl // Lindi /()
8. The role of a pipeline is to use the standard output of one process as the standard input of another process. ()
9. The default matching variable for pattern matching is $ &()
10. The stat parameter of Perl's built-in function can be a file handle or file name. ()
11. programs programmed with Perl are highly portable, so they can be correctly run on any computer system without modification ()
12. The statement $ point = {1 => 'hello', 2 => 'World'} creates a reference to the hash structure. ()
13. Perl built-in functions are all placed in the module. ()
14. The communication between the server and the browser can only be conducted in a single answer. ()
15. Use the Redirect function in the CGI Module to implement HTTP redirection. ()
(Answer)
Iii. multiple choice questions
1. Which of the following expressions are true when the string variable $ STR contains a substring '123? ()
(1) $ STR = ~ /10mm/
(2) $ STR = ~ // DMM/
(3) $ STR = ~ // D? M */
(4) index ($ STR, '20140901 ')! =-1
2. Which of the following strings can be matched by mode/(/d {4})-(/d {1, 2})-(/d {1, 3? ()
(1) Happy 2001-02-27
(2) Today is 2001-2-7
(3) 99-2-7
(4) 02-27
3. Basic data types in Perl :()
(1) scalar.
(2) array.
(3) Hash structure.
(4) file handle.
4. The angle brackets operator (<>) can be used ()
(1) read the file.
(2) pattern matching Operator
(3) Search for the specified file.
(4) program comments.
5. Which of the following code can be used to create a reference to the list (1 .. 6? ()
(1) $ point = (1 .. 6 );
(2) @ array = (1 .. 6 );
$ Point = // @ array;
(3) My $ point
{
My @ array = (1 .. 6)
$ Point = @ array;
}
(4) $ point = [1 .. 6];

6. When your cgi program cannot run, what may be the following situations? ()
(1) enter the CGI program URL in the address bar of the browser.
(2) there is an error in the CGI program.
(3) The server does not support CGI programs.
(4) the browser has a problem.
7. The difference between using the get and post methods to submit a form is ()
(1) The get method decodes the form value and puts it into the URL for submission. The post method is directly transmitted to the server.
(2) The get method directly transmits the form value to the server, while the POST method decodes the form and submits it in the URL.
(3) The get method can only submit a limited value, while the POST method can submit any number of values to the server.
(4) Get can call another CGI program by setting the value of the form to the address of the CGI program, but the POST method cannot.
8. What should we pay attention to in order to keep CGI programs as secure as possible? ()
(1) You cannot use a common cgi form to send confidential information.
(2) Compile the CGI program into an execution file.
(3 #! Add the-T switch to the row.
(4) verify important data on the server.
9. Which of the following statements about hidden domains are true? ()
(1) A form containing hidden fields can only be submitted to the server using the POST method.
(2) If an HTML code <input type = hidden name = myname value = 1> defines a hidden field.
(3) The user cannot change the value of the hidden domain.
(4) CGI programs only use hidden domains to record operations performed by users on their sites.
10. The purpose of cookie is ()
(1) temporarily Save User-related information.
(2) replace files and databases.
(3) No effect.
(4) directly control the browser.
11. The limitation of Cook lies in ()
(1) cannot be deleted, edited, or viewed by users.
(2) The survival time is limited.
(3) It can only be received by the server that sends the cookie.
(4) Not all browsers support cookies.
12. Which of the following statements about sending emails in CGI programs are true? ()
(1) only UNIX systems can run the CGI program that sends emails in MTA mode.
(2) The mail sending program written by the net: SMTP module can run on any network operating system.
(3) sending an email using MTA means that the CGI program calls an external MTA program to send an email.
(4) Net: The send_mail function is used in the SMTP module to send emails.
13. Which of the following methods can be used to call an external program edit? ()
(1) system ("edit ");
(2) $ Var = QX {edit };
(3) "edit ";
(4) Open (myfile, "Edit | ");
14. Which methods can be used to interrupt a Perl program? ()
(1) Use the exit function.
(2) Use the die function.
(3) Use the last function.
(4) No way.
15. Which of the following statements about the sharp extension operator is false? ()
(1) $ Var = <stdout>;
(2) $ Var = <stdin>;
(3) $ Var = <stderr>;
(4) $ Var = <>;
(Answer)
Iv. Practical questions
1. We may feel that adding a line number is troublesome during the program, but it is quite convenient for the source program to have a line number during debugging and reading. Please write a program, you can add a row number to a text file. Use the command line method to send the original text file name and the text file name generated after the line number to this program.
2. Perl itself does not contain a text editor. However, when writing programs, we constantly write operating system commands. switching between the text editor and the perl interpreter will affect the speed and thinking, however, we can use Perl to bond the text editor with the perl interpreter. Compile a program to automatically call the perl interpreter in the source program compiled in the text editor. After you finish reading the result, return to the text editor to continue modifying the source program. The source program name you need to write is transmitted to this program using the command line method.
3. Compile a CGI program for online karaoke. You can use the drop-down list box on the HTML page to perform karaoke. The CGI program plays different songs based on your choice.
4. Compile an automatic link system with CGI program to save the submitted website address, website name, website image, and other information in the file and display it during user access.

Answers to questions in 24 hours of Perl programming
I. single answer
1. (3) 2. (3) 3. (2) 4. (3) 5. (1) 6. (2) 7. (1) 8. (3) 9. (4) 10, (1) 11, (3) 12, (1) 13, (2) 14, (2) 15, (1 ), because an array containing two elements in a scalar context returns the size of the array 2

(Return)
Ii. Answer to the answer to the question
1. Error. When comparing strings, Relational operators (! =), And the (NE) Statement is print 'No! 'If ($ a ne 'hello ');
2. An error occurs. (+) is a numeric operator that connects strings to apply the operator (.)
3. Error.
4. Yes.
5. Error. (|) has a higher priority than (and ).
6. Incorrect. The file handle cannot be defined using the My operator.
7. Yes.
8. Yes.
9. Error. It should be $ _
10. Yes.
11. Error. When code is dependent on a specific operating system, you need to modify it when porting it.
12. Yes.
13. Error.
14. If an error occurs, the CGI program can also use the server push method.
15. Yes.

(Return)
Iii. Multiple answer questions
1. (1) (2) (3) (4) 2. (1) (2) 3. (1) (2) (3) 4. (1) (3) 5, (2) (4) 6, (1) (2) (3) (4) 7, (1) (3) (4) 8. (1) (3) (4) 9. (2) (3) (4)
10. (1) 11, (2) (4) 11, (2) (3) (4) 12, (2) (3) (4) 13, (1) (2) (4)
14. (1) (2) (3) 15. (1) (3)

(Return)
4. Implement answers to questions

1. The source program is as follows:
# Addnum. pl
#! /Usr/bin/perl
My $ text, source, DEST, $ I = 1;
@ Argv = 2 or die "the number of parameter can but is 2! /N "; # the number of parameters must be equal to 2.
Open (source, $ argv [0]) | die $ !; # Open the source file.
Open (DEST, "> $ argv [1]") | die $ !; # Create a target file.
While (defined ($ text = <source>) # Read a row from the original file to $ text.
{
Print DEST "$ I: $ text"; # write data to the target file.
$ I ++; # Add a row number.
}
Print "file modify done! ";
Close (source); # Close the source file.
Close (DEST); # Close the target file.

2. The source program is as follows:
#! /Usr/contrib/bin/perl-W
My $ got;
@ Argv = 1 or die "the number of parameter can but is 1! /N "; # the number of parameters must be equal to 1.
While ($ got ne 'Q' and $ got ne 'q') # Press Q to exit.
{
System ("Edit $ argv [0]");
System ("Perl $ argv [0]");
Print 'enter Q to quit, enter other to continue :';
$ Got = <stdin>;
Chomp $ got;
}
Exit;

3. The source program is as follows:
# Play. cgi
#! /Usr/contrib/bin/perl-W
Use strict;
Use cgi qw (: All );
My (@ song, $ I, $ index );
@ Song = ('xieyuxin. Mid ', 'tianxianzi. mpg ');
$ Index = 0;
Print header;
Print start_html ("On-Demand Songs ");
$ Index = param ('d1 ') if (PARAM );
Print "<bgsound src = $ song [$ Index] autostart = true loop = infinite> ";
For ($ I = 0; $ I <@ song; $ I ++)
{
$ Song [$ I] = '';
$ Song [$ I] = 'selected' if ($ I = $ index );
}
Print <end_page_play;
<Form method = post action = play. cgi>
<P> <center> <select size = 1 name = D1 onchange = this. Form. Submit ();>
<Option value = 0 $ song [0]> Song 1 </option>
<Option value = 1 $ song [1]> song 2 </option>
</SELECT> </center> </P>
</Form>
End_page_play
Print end_html;

4. The source program is as follows:
File 1 (HTML page logo. htm)
<HTML>
<Head>
<Title> Registration link closed </title>
</Head>
<Body text = "#000000" bgcolor = "# ffffcc">
<Form method = "Post" Action = "friend. cgi">
<P> <center> website name <input type = "text" name = "name" size = "20"> </center> </P>
<P> <center> website address <input type = "text" name = "adderss" size = "20"> </center> </P>
<P> <center> website images <input type = "text" name = "pic" size = "20"> </center> </P>
<P> <center> <input type = "Submit" value = "Submit" name = "B1"> <input type = "reset" value = "rewrite all" name =" b2 "> </center> </P>
</Form>
</Body>
</Html>

File 2 (friend. cgi)
# Friend. cgi
#! /Usr/contrib/bin/perl-W
# Program Design)
Use strict;
Use cgi qw (: All );
Use fcntl QW (: flock );
My ($ name, $ adderss, $ pic, $ line, $ I );
Print header;
Print start_html ("Link ");
Open (friend, "+> friend.txt ");

If (PARAM)
{
$ Name = param ('name ');
$ Adderss = param ('adderss ');
$ PIC = param ('pic ');
Print friend "$ name/N ";
Print friend "$ adderss/N ";
Print friend "$ PIC/N ";
Seek (friend, 0, 0 );
}

Print '<Table border = "1" width = "100%"> ';
While ($ end)
{
Last if (! Defined ($ name = <friend> ));
Last if (! Defined ($ adderss = <friend> ));
Last if (! Defined ($ PIC = <friend> ));
Print <end_page_friend;
<Tr>
<TD> <a href = $ adderss> <center> </center>
<P> <center> $ name </center> </P> </a>
</TD>
</Tr>
End_page_friend
}
Print '</table> ';
Close (friend );
Print end_html;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.