亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch5.htm

?? prrl 5 programs codes in the book
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
<HTML>

<HEAD>

<TITLE>Chapter 5 -- FuNCtions</TITLE>



<META>

</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">

<H1><FONT SIZE=6 COLOR=#FF0000>Chapter&nbsp;5</FONT></H1>

<H1><FONT SIZE=6 COLOR=#FF0000>FuNCtions</FONT></H1>

<HR>

<P>

<CENTER><B><FONT SIZE=5>CONTENTS</FONT></B></CENTER>

<UL>

<UL>

<LI><A HREF="#ExampleUsingtheParameterArray">

Example: Using the Parameter Array (@_)</A>

<LI><A HREF="#ExamplePassingParametersbyRefereNCe">

Example: Passing Parameters by RefereNCe</A>

<LI><A HREF="#ExampleScopeofVariables">

Example: Scope of Variables</A>

<LI><A HREF="#ExampleUsingaListasaFuNCtionParameter">

Example: Using a List as a FuNCtion Parameter</A>

<LI><A HREF="#ExampleNestingFuNCtionCalls">

Example: Nesting FuNCtion Calls</A>

<LI><A HREF="#ExampleUsingaPrivateFuNCtion">

Example: Using a Private FuNCtion</A>

</UL>

<LI><A HREF="#StringFuNCtions">

String FuNCtions</A>

<UL>

<LI><A HREF="#ExampleChangingaStringsValue">

Example: Changing a String's Value</A>

<LI><A HREF="#ExampleSearchingaString">

Example: Searching a String</A>

</UL>

<LI><A HREF="#ArrayFuNCtions">

Array FuNCtions</A>

<UL>

<LI><A HREF="#ExamplePrintinganAssociativeArray">

Example: Printing an Associative Array</A>

<LI><A HREF="#ExampleCheckingtheExisteNCeofanElement">

Example: Checking the ExisteNCe of an Element</A>

</UL>

<LI><A HREF="#Summary">

Summary</A>

<LI><A HREF="#ReviewQuestions">

Review Questions</A>

<LI><A HREF="#ReviewExercises">

Review Exercises</A>

</UL>



<HR>

<P>

This chapter takes a look at <I>fuNCtions</I>. FuNCtions are blocks

of codes that are given names so that you can use them as needed.

FuNCtions help you to organize your code into pieces that are

easy to understand and work with. They let you build your program

step by step, testing the code along the way.

<P>

After you get the idea for a program, you need to develop a program

outline-either in your head or on paper. Each step in the outline

might be one fuNCtion in your program. This is called <I>modular

programming</I>. Modular programming is very good at allowing

you to hide the details so that readers of your source code can

understand the overall aim of your program.

<P>

For instaNCe, if your program has a fuNCtion that calculates the

area of a circle, the following line of code might be used to

call it:

<BLOCKQUOTE>

<PRE>

$areaOfFirstCircle = areaOfCircle($firstRadius);

</PRE>

</BLOCKQUOTE>

<P>

By looking at the fuNCtion call, the reader knows what the program

is doing. Detailed understanding of the actual fuNCtion is not

needed.<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Tip</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

Well thought out fuNCtion and variable names help people to understand your program. If the line of code was</BLOCKQUOTE>

<BLOCKQUOTE>

<TT>$areaFC = areaCirc($fRad);</TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

its meaning would not be as clear.</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Note</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

Calling a fuNCtion means that Perl stops executing the current series of program lines. Program flow jumps into the program code inside the fuNCtion. When the fuNCtion is finished, Perl jumps back to the point at which the fuNCtion call was made. Program 
execution continues from that point onward.</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

Let's look at the fuNCtion call a little closer. The first thing

on the line is a scalar variable and an assignment operator. You

already know this means Perl assigns the value on the right of

the assignment operator to <TT>$areaOfFirstCircle</TT>.

But, what exactly is on the right?

<P>

The first thing you see is the fuNCtion name <TT>areaOfCircle()</TT>.

The parentheses directly to the right and no <TT>$</TT>,

<TT>@</TT>, or <TT>%</TT>

beginning the name indicates that this is a fuNCtion call. Inside

the parentheses is a list of parameters or values that get passed

to the fuNCtion. You can think of a parameter just like a football.

When passed, the receiver (for example, the fuNCtion) has several

options: run (modify it in some way), pass (call other routines),

fumble (call the error handler).<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Note</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

Perl enables you to use the <TT>&amp;</TT> character to start fuNCtion names, and in a few cases it is needed. Those few situations that the <TT>&amp;</TT> character is needed are beyond the scope of this book.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

Listing 5.1 shows a short program that calls and defines the <TT>areaOfCircle()</TT>

fuNCtion.

<P>

<IMG SRC="pseudo.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/pseudo.gif" BORDER=1 ALIGN=RIGHT><p>

<BLOCKQUOTE>

<I>Assign </I><TT><I>$areaOfFirstCircle</I></TT><I>

the value that is returned by the fuNCtionareaOfCircle().<BR>

Print </I><TT><I>$areaOfFirstCircle</I></TT><I>.

<BR>

Define the areaOfCircle() fuNCtion.<BR>

Get the first parameter from the </I><TT><I>@_</I></TT><I>

 parameter array.<BR>

Calculate the area and return the new value.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 5.1&nbsp;&nbsp;05LST01.PL-Calculating the Area of a

Circle<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

$areaOfFirstCircle = areaOfCircle(5);

print(&quot;$areaOfFirstCircle\n&quot;);



sub areaOfCircle {

    $radius = $_[0];

    return(3.1415 * ($radius ** 2));

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

This program prints:

<BLOCKQUOTE>

<PRE>

78.7375

</PRE>

</BLOCKQUOTE>

<P>

The fact that something prints tells you that the program flow

returned to the print line after calling the <TT>areaOfCircle()</TT>

fuNCtion.

<P>

A fuNCtion definition is very simple. It consists of:

<BLOCKQUOTE>

<PRE>

sub fuNCtionName {

}

</PRE>

</BLOCKQUOTE>

<P>

That's it. Perl fuNCtion definitions never get any more complex.

<P>

The complicated part comes when dealing with parameters. <I>Parameters

</I>are values passed to the fuNCtion (remember the football?).

The parameters are specified inside the parentheses that immediately

follow the fuNCtion name. In Listing 5.1, the fuNCtion call was

<TT>areaOfCircle(5)</TT>. There was

only one parameter, the number 5. Even though there is only one

parameter, Perl creates a parameter array for the fuNCtion to

use.

<P>

Inside the <TT>areaOfCircle()</TT>

fuNCtion, the parameter array is named <TT>@_</TT>.

All parameters specified during the fuNCtion call are stored in

the <TT>@_ </TT>array so that the

fuNCtion can retrieve them. Our small fuNCtion did this with the

line:

<BLOCKQUOTE>

<PRE>

$radius = $_[0];

</PRE>

</BLOCKQUOTE>

<P>

This line of code assigns the first element of the <TT>@_

</TT>array to the <TT>$radius</TT>

scalar.<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Note</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

Because parameters always are passed as lists, Perl fuNCtions also are referred to as list operators. And, if only one parameter is used, they are sometimes referred to as unary operators. However, I'll continue to call them fuNCtions and leave the finer 
points of distiNCtion to others.</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

The next line of the fuNCtion:

<BLOCKQUOTE>

<PRE>

return(3.1415 * ($radius ** 2));

</PRE>

</BLOCKQUOTE>

<P>

calculates the circle's area and returns the newly calculated

value. In this case, the returning value is assigned to the <TT>$areaOfFirstCircle</TT>

scalar variable.<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Note</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

If you prefer, you don't need to use the <TT>return()</TT> fuNCtion to return a value because Perl automatically returns the value of the last expression evaluated. I prefer to use the <TT>return()</TT> fuNCtion and be explicit so that there is no 
mistaking my intention.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

You may have used programming languages that distinguish between

a fuNCtion and a subroutine, the differeNCe being that a fuNCtion

returns a value and a subroutine does not. Perl makes no such

distiNCtions. Everything is a fuNCtion-whether or not it returns

a value.

<H3><A NAME="ExampleUsingtheParameterArray">

Example: Using the Parameter Array (@_)</A></H3>

<P>

All parameters to a fuNCtion are stored in an array called <TT>@_</TT>.

One side effect of this is that you can find out how many parameters

were passed by evaluating <TT>@</TT>

in a scalar context.

<P>

<IMG SRC="pseudo.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/pseudo.gif" BORDER=1 ALIGN=RIGHT><p>

<BLOCKQUOTE>

<I>Call the </I><TT><I>firstSub()</I></TT><I>

fuNCtion with a variety of parameters.<BR>

Define the </I><TT><I>firstSub()</I></TT><I>

fuNCtion<BR>

Assign </I><TT><I>$numParameters</I></TT><I>

the number of elements in the array @_.<BR>

Print out how any parameters were passed.</I>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

firstSub(1, 2, 3, 4, 5, 6);

firstSub(1..3);

firstSub(&quot;A&quot;..&quot;Z&quot;);



sub firstSub {

    $numParameters = @_ ;

    print(&quot;The number of parameters is $numParameters\n&quot;);

}

</PRE>

</BLOCKQUOTE>

<P>

This program prints out:

<BLOCKQUOTE>

<PRE>

The number of parameters is 6

The number of parameters is 3

The number of parameters is 26

</PRE>

</BLOCKQUOTE>

<P>

Perl lets you pass any number of parameters to a fuNCtion. The

fuNCtion decides which parameters to use and in what order. The

<TT>@_</TT> array is used like any

other array.

<P>

Let's say that you want to use scalar variables to refereNCe the

parameters so you don't have to use the clumsy and uninformative

<TT>$_ [0]</TT> array element notation.

By using the assignment operator, you can assign array elements

to scalars in one easy step.

<P>

<IMG SRC="pseudo.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/pseudo.gif" BORDER=1 ALIGN=RIGHT><p>

<BLOCKQUOTE>

<I>Call the </I><TT><I>areaOfRectangle()</I></TT><I>

fuNCtion with varying parameters.<BR>

Define the </I><TT><I>areaOfRectangle()</I></TT><I>

fuNCtion.<BR>

Assign the first two elements of </I><TT><I>@_</I></TT><I>

to </I><TT><I>$height</I></TT><I>

and </I><TT><I>$width</I></TT><I>

respectively.<BR>

Calculate the area.<BR>

Print the three variables: </I><TT><I>$height</I></TT><I>,

</I><TT><I>$width</I></TT><I>, and

</I><TT><I>$area</I></TT><I>.</I>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

areaOfRectangle(2, 3);

areaOfRectangle(5, 6);



sub areaOfRectangle {

    ($height, $width) = @_ ;



    $area = $height * $width;



    print(&quot;The height is $height. The width is $width.

        The area is $area.\n\n&quot;);

}

</PRE>

</BLOCKQUOTE>

<P>

This program prints out:

<BLOCKQUOTE>

<PRE>

The height is 2. The width is 3.

        The area is 6.



The height is 5. The width is 6.

        The area is 30.

</PRE>

</BLOCKQUOTE>

<P>

The statement <TT>($height,$width) = @_;</TT>

does the array element to scalar assignment. The first element

is assigned to <TT>$height</TT>, and

the second element is assigned to <TT>$width</TT>.

After the assignment is made, you can use the scalar variables

to represent the parameters.

<H3><A NAME="ExamplePassingParametersbyRefereNCe">

Example: Passing Parameters by RefereNCe</A></H3>

<P>

Using scalar variables inside your fuNCtions is a good idea for

another reason-besides simple readability coNCerns. When you change

the value of the elements of the <TT>@ </TT>

array, you also change the value of the parameters in the rest

of the program. This is because Perl parameters are called by

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
五月激情综合色| 国产成人精品免费在线| 欧美午夜一区二区| 亚洲二区视频在线| 欧美日韩国产首页在线观看| 午夜激情综合网| 91精品国产综合久久久久| 亚洲18女电影在线观看| 国产精品欧美一区喷水| 国产成人午夜视频| 亚洲美女屁股眼交| 欧美巨大另类极品videosbest| 日韩国产在线观看一区| 3d成人动漫网站| 国产成人精品免费| 一区二区三区四区精品在线视频 | 91麻豆国产福利精品| 亚洲一卡二卡三卡四卡无卡久久| 337p亚洲精品色噜噜狠狠| 久久国产成人午夜av影院| 国产精品乱码一区二区三区软件 | 粉嫩av一区二区三区在线播放| 国产精品国产自产拍高清av王其 | 91精品国产免费| 国产精品一区二区不卡| 亚洲欧美偷拍另类a∨色屁股| 欧美欧美午夜aⅴ在线观看| 久久er99热精品一区二区| 亚洲人吸女人奶水| 日韩精品专区在线影院重磅| 99国产精品久久久久久久久久久| 男男视频亚洲欧美| 亚洲人成影院在线观看| 精品伦理精品一区| 在线观看91精品国产入口| 精品亚洲欧美一区| 亚洲一区二区偷拍精品| 久久精品水蜜桃av综合天堂| 欧美精品成人一区二区三区四区| 成人网男人的天堂| 九色综合国产一区二区三区| 伊人性伊人情综合网| 久久久蜜臀国产一区二区| 欧美日韩亚洲另类| 91亚洲国产成人精品一区二区三| 久久精品国产一区二区| 亚洲资源中文字幕| 国产精品久久久99| 欧美精品一区二区久久久| 日本韩国欧美三级| 成人高清免费观看| 国产自产v一区二区三区c| 亚洲bt欧美bt精品| 一区二区三区色| 国产精品乱码人人做人人爱 | 日韩午夜激情av| 欧美三级视频在线观看| 91在线porny国产在线看| 狠狠色2019综合网| 蜜臀av在线播放一区二区三区| 亚洲激情第一区| 国产主播一区二区| 精品在线播放午夜| 美女爽到高潮91| 日产欧产美韩系列久久99| 午夜精品国产更新| 亚洲第一成年网| 亚洲一区二区三区三| 一区二区三区四区不卡视频 | 欧美日本乱大交xxxxx| 欧美影视一区在线| 日本大香伊一区二区三区| 91在线丨porny丨国产| 成人免费av网站| 成人精品免费视频| 91亚洲国产成人精品一区二区三| 99精品国产91久久久久久| 99re8在线精品视频免费播放| 成人激情午夜影院| 不卡一区在线观看| 91丨九色丨蝌蚪丨老版| 94-欧美-setu| 欧美在线观看视频一区二区三区 | 欧美电影在线免费观看| 欧美日韩视频在线第一区 | 国产精品久久久久久久浪潮网站 | 一区二区欧美在线观看| 亚洲自拍偷拍综合| 日韩精品91亚洲二区在线观看| 肉丝袜脚交视频一区二区| 日本成人中文字幕| 激情偷乱视频一区二区三区| 国产麻豆精品一区二区| 国产成人高清在线| 99久久免费国产| 欧美三级视频在线播放| 在线不卡欧美精品一区二区三区| 欧美一级片在线观看| 久久久久久久久99精品| 亚洲色图在线视频| 午夜影视日本亚洲欧洲精品| 免费不卡在线观看| 风间由美性色一区二区三区| 色综合天天狠狠| 欧美精品tushy高清| 国产日韩av一区二区| 亚洲日本在线天堂| 蜜桃精品视频在线| 成人午夜激情视频| 欧美吻胸吃奶大尺度电影| 精品国产凹凸成av人网站| 中文字幕+乱码+中文字幕一区| 艳妇臀荡乳欲伦亚洲一区| 日韩av一区二区在线影视| 国产91精品一区二区| 欧美日韩一本到| 国产精品素人视频| 天堂精品中文字幕在线| 国产成人aaa| 欧美日韩国产高清一区二区 | 国产一区二区三区精品视频| 91网站在线观看视频| 日韩欧美国产一区二区在线播放| 国产精品视频观看| 久久精品国产精品亚洲精品| 一本大道av伊人久久综合| 亚洲精品在线观看网站| 亚洲精品福利视频网站| 国产精品18久久久久久久久久久久 | 欧美在线观看视频在线| 国产亚洲精品bt天堂精选| 亚洲午夜免费电影| 国产成人亚洲综合a∨猫咪| 欧美一区二区日韩| 亚洲激情在线播放| 粉嫩aⅴ一区二区三区四区| 日韩欧美国产电影| 亚洲一区二区三区在线看| 成人免费视频app| 精品福利av导航| 午夜国产精品一区| 色老头久久综合| 中文字幕一区二区三区乱码在线| 久久成人羞羞网站| 4438x亚洲最大成人网| 一区二区三区av电影 | 91视频精品在这里| 国产精品美女久久久久久久久久久| 日本午夜精品视频在线观看 | av中文一区二区三区| 久久久噜噜噜久久人人看 | 国产精品一二二区| xfplay精品久久| 久久疯狂做爰流白浆xx| 51精品视频一区二区三区| 亚洲成a天堂v人片| 欧美日韩一区二区三区高清| 一区二区三区在线视频播放| av动漫一区二区| 中文字幕一区二区三区色视频| 丁香婷婷综合色啪| 国产精品久久久久三级| 成人av网站在线观看免费| 国产精品久久午夜夜伦鲁鲁| 国产伦精品一区二区三区免费迷 | 欧美成人艳星乳罩| 欧美96一区二区免费视频| 91精品国产一区二区三区| 午夜精品免费在线| 欧美蜜桃一区二区三区| 婷婷开心激情综合| 欧美精品欧美精品系列| 欧美aaaaaa午夜精品| 欧美videos大乳护士334| 紧缚捆绑精品一区二区| 国产欧美精品在线观看| 成人短视频下载| 国产精品国产三级国产有无不卡| 97国产一区二区| 一二三区精品视频| 欧美日韩在线播放一区| 麻豆精品一区二区av白丝在线| 亚洲成人激情自拍| 欧美一区二区国产| 久久精品国产99久久6| 欧美激情一区在线观看| 99久久精品国产导航| 亚洲一二三四久久| 7777精品伊人久久久大香线蕉超级流畅 | 97国产一区二区| 亚洲动漫第一页| 日韩精品一区二区三区视频播放 | 国产日韩欧美精品一区| 99精品热视频| 日韩国产一区二| 中文天堂在线一区| 欧美视频你懂的| 国产一区二区不卡| 亚洲精品免费在线| 欧美成人乱码一区二区三区|