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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? ch5.htm

?? prrl 5 programs codes in the book
?? HTM
?? 第 1 頁(yè) / 共 4 頁(yè)
字號(hào):
<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

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产福利一区在线| 精品视频123区在线观看| 成人精品免费网站| 99国产精品国产精品毛片| 91成人看片片| 精品国产a毛片| 1024成人网| 日本不卡不码高清免费观看| 国内精品久久久久影院薰衣草 | 日韩欧美精品在线视频| 26uuu久久天堂性欧美| 国产精品久久久久久户外露出| 一区二区三区四区激情| 男女男精品视频| 99re在线精品| 欧美一区二区久久久| 国产免费成人在线视频| 精品日本一线二线三线不卡| 欧美大尺度电影在线| 一区二区三区色| 国产成人免费视频网站高清观看视频 | 国产欧美日韩视频在线观看| 亚洲色图制服丝袜| 国产在线国偷精品免费看| 欧美主播一区二区三区美女| 久久久精品国产免大香伊| 亚洲va在线va天堂| 91热门视频在线观看| 久久人人97超碰com| 天天影视色香欲综合网老头| av电影在线观看完整版一区二区| 777色狠狠一区二区三区| 亚洲色大成网站www久久九九| 国产九九视频一区二区三区| 成年人国产精品| 国产精品99久久久久久久女警 | 欧美乱妇15p| 亚洲精品第1页| 成人中文字幕在线| 欧美高清在线精品一区| 国产成人综合自拍| 国产精品每日更新| 粉嫩av一区二区三区粉嫩| 久久精品亚洲一区二区三区浴池| 久久黄色级2电影| 国产亚洲欧美日韩日本| 国产精品一区二区不卡| 中日韩免费视频中文字幕| 国产91丝袜在线播放九色| 欧美主播一区二区三区美女| 国产精品久久综合| 精品制服美女久久| 欧美电影免费观看高清完整版| 午夜伊人狠狠久久| 91麻豆精品国产91久久久久久| 亚洲精品乱码久久久久| 懂色av一区二区三区免费看| 精品对白一区国产伦| 国产综合成人久久大片91| 久久婷婷成人综合色| 国产99久久久国产精品潘金网站| 欧美日韩精品一区二区| 婷婷综合另类小说色区| 日韩视频国产视频| 看国产成人h片视频| 久久精品男人的天堂| 国产剧情一区在线| 国产精品色眯眯| 在线观看亚洲精品视频| 日韩精品一卡二卡三卡四卡无卡| 日韩欧美激情一区| 久久99热99| 国产欧美在线观看一区| 91精彩视频在线观看| 亚洲精品老司机| 精品欧美乱码久久久久久1区2区| 国产一区高清在线| 亚洲自拍偷拍麻豆| 国产偷国产偷亚洲高清人白洁 | 日韩欧美国产高清| zzijzzij亚洲日本少妇熟睡| 日韩美女啊v在线免费观看| 欧美日韩视频在线第一区| 国产一区二区主播在线| 午夜精品久久久久久久99樱桃| 精品理论电影在线观看| 色哟哟国产精品| 久久 天天综合| 一区二区在线观看视频| 久久久久久久国产精品影院| 韩国毛片一区二区三区| 欧美日韩一区不卡| 国产盗摄一区二区| 日韩电影免费在线看| 中文字幕一区二区三区不卡| 日韩精品一区二区三区在线观看| 91福利国产成人精品照片| 国产91在线|亚洲| 久久av老司机精品网站导航| 一区二区视频在线看| 欧美一卡2卡三卡4卡5免费| 色婷婷av一区二区三区之一色屋| 国产麻豆成人传媒免费观看| 午夜a成v人精品| 亚洲伦理在线精品| 18涩涩午夜精品.www| 亚洲欧美一区二区在线观看| 久久久久久免费网| 久久久久久久电影| 久久久久久久精| 国产亚洲一区二区三区在线观看| 欧美大片免费久久精品三p| 色88888久久久久久影院野外| 色婷婷久久久综合中文字幕| 色哟哟一区二区| 欧美丰满嫩嫩电影| 日韩女优制服丝袜电影| 久久久久久久久伊人| 国产婷婷一区二区| 综合婷婷亚洲小说| 亚洲国产成人av好男人在线观看| 亚洲www啪成人一区二区麻豆| 奇米影视一区二区三区小说| 韩日av一区二区| 色88888久久久久久影院按摩| 91污片在线观看| 欧美一级免费大片| 日本一区二区三区四区| 日韩高清欧美激情| 国产91色综合久久免费分享| 色婷婷av久久久久久久| 欧美美女视频在线观看| 久久先锋资源网| 亚洲成人免费视频| 蜜臀va亚洲va欧美va天堂| 成人动漫av在线| 欧美区在线观看| 国产精品久久久久久久蜜臀| 亚洲成在线观看| 奇米影视在线99精品| 国产高清久久久| 欧美肥胖老妇做爰| 国产精品久久久久久久久免费桃花| 亚洲成年人网站在线观看| 国产精品一区专区| 色婷婷亚洲一区二区三区| 国产色产综合产在线视频| 亚洲国产一区二区三区| 粉嫩av亚洲一区二区图片| 欧美一级片在线看| 亚洲成人tv网| 色婷婷精品久久二区二区蜜臀av| 久久影院电视剧免费观看| 日本不卡的三区四区五区| 欧美午夜一区二区三区| 亚洲精品v日韩精品| 国产一区二区电影| 国产亚洲美州欧州综合国| 亚洲欧洲另类国产综合| 亚洲午夜电影网| 国产精品1024| 久久嫩草精品久久久久| 久久精品国产久精国产爱| 日韩亚洲电影在线| 久久99精品久久久久久国产越南| 91无套直看片红桃| 亚洲综合色成人| 欧美自拍丝袜亚洲| 亚洲精品久久嫩草网站秘色| 色婷婷综合激情| 亚洲妇女屁股眼交7| 在线免费观看一区| 日韩av在线免费观看不卡| 日韩欧美国产一区二区在线播放| 99久久久精品| 亚洲永久免费视频| 日韩欧美一级二级三级久久久| 午夜欧美在线一二页| 欧美不卡视频一区| 成人一区二区在线观看| 一区二区三区精品| 日韩欧美中文字幕一区| 国产成人亚洲综合a∨婷婷| 中文字幕成人网| 欧美日韩在线播放一区| 精品系列免费在线观看| 自拍偷拍欧美激情| 91精品国产91久久久久久最新毛片| 久久66热偷产精品| 亚洲福利一区二区三区| 亚洲欧洲精品一区二区三区不卡| 91麻豆精品国产自产在线观看一区 | 一区二区三区不卡在线观看| 26uuu欧美日本| 日韩美女主播在线视频一区二区三区| 日本高清视频一区二区| av网站免费线看精品| 国产制服丝袜一区| 狠狠色丁香婷婷综合久久片| 婷婷开心激情综合|