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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ch5.htm

?? prrl 5 programs codes in the book
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
refereNCe. When parameters are called by refereNCe, changing their

value in the fuNCtion also changes their value in the main program.

Listing 5.2 shows how this happens.

<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>Create an array with 6 elements.<BR>

Print the elements of the array.<BR>

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

fuNCtion.<BR>

Print the elements of the array.<BR>

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

fuNCtion.<BR>

Change the values of the first two elements of </I><TT><I>@_</I></TT><I>.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 5.2&nbsp;&nbsp;05LST02.PL-Using the @Array to Show

Call by RefereNCe<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

@array = (0..5);

print(&quot;Before fuNCtion call, array = @array\n&quot;);

firstSub(@array);

print(&quot;After fuNCtion call, array =  @array\n&quot;);



sub firstSub{

    $_[0] = &quot;A&quot;;

    $_[1] = &quot;B&quot;;

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

This program prints:

<BLOCKQUOTE>

<PRE>

Before fuNCtion call, array =  0 1 2 3 4 5

After fuNCtion call, array =   A B 2 3 4 5

</PRE>

</BLOCKQUOTE>

<P>

You can see that the fuNCtion was able to affect the <TT>@array</TT>

variable in the main program. Generally, this is considered bad

programming practice because it does not isolate what the fuNCtion

does from the rest of the program. If you change the fuNCtion

so that scalars are used inside the fuNCtion, this problem goes

away. List-ing 5.3 shows how to redo the program in Listing 5.2

so scalars are used inside the 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>Create an array with 6 elements.<BR>

Print the elements of the array.<BR>

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

fuNCtion.<BR>

Print the elements of the array.<BR>

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

fuNCtion.<BR>

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

to </I><TT><I>$firstVar</I></TT><I>

and </I><TT><I>$secondVar</I></TT><I>.

<BR>

Change the values of the scalar variables.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 5.3&nbsp;&nbsp;05LST03.PL-Using Scalars Instead of

the @_ Array Inside FuNCtions<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

@array = (0..5);

print(&quot;Before fuNCtion call, array = @array\n&quot;);

firstSub(@array);

print(&quot;After fuNCtion call, array =  @array\n&quot;);



sub firstSub{

    ($firstVar, $secondVar) = @_ ;



    $firstVar = &quot;A&quot;;

    $secondVar = &quot;B&quot;;

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

This program prints:

<BLOCKQUOTE>

<PRE>

Before fuNCtion call, array =  0 1 2 3 4 5

After fuNCtion call, array =   0 1 2 3 4 5

</PRE>

</BLOCKQUOTE>

<P>

This example shows that the original <TT>@array</TT>

variable is left untouched. However, another problem has quietly

arisen. Let's change the program a little so the values of <TT>$firstVar</TT>

are printed before and after the fuNCtion call. Listing 5.4 shows

how changing a variable in the fuNCtion affects the main program.

<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 a value to </I><TT><I>$firstVar</I></TT><I>.

<BR>

Create an array with 6 elements.<BR>

Print the elements of the array.<BR>

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

fuNCtion.<BR>

Print the elements of the array.<BR>

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

fuNCtion.<BR>

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

to </I><TT><I>$firstVar</I></TT><I>

and </I><TT><I>$secondVar</I></TT><I>.

<BR>

Change the values of the scalar variables.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 5.4&nbsp;&nbsp;05LST04.PL-Using Variables in FuNCtions

Can Cause Unexpected Results<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

$firstVar = 10;

@array    = (0..5);



print(&quot;Before fuNCtion call\n&quot;);

print(&quot;\tfirstVar = $firstVar\n&quot;);

print(&quot;\tarray    = @array\n&quot;);



firstSub(@array);



print(&quot;After fuNCtion call\n&quot;);

print(&quot;\tfirstVar = $firstVar\n&quot;);

print(&quot;\tarray    = @array\n&quot;);



sub firstSub{

    ($firstVar, $secondVar) = @_ ;



    $firstVar = &quot;A&quot;;

    $secondVar = &quot;B&quot;;

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

This program prints:

<BLOCKQUOTE>

<PRE>

Before fuNCtion call

        firstVar = 10

        array    = 0 1 2 3 4 5



After fuNCtion call

        firstVar = A

        array    = 0 1 2 3 4 5

</PRE>

</BLOCKQUOTE>

<P>

By using the <TT>$firstVar</TT> variable

in the fuNCtion you also change its value in the main program.

By default, all Perl variables are accessible everywhere inside

a program. This ability to globally access variables can be a

good thing at times. It does help when trying to isolate a fuNCtion

from the rest of your program. The next section shows you how

to create variables that can only be used inside fuNCtions.

<H3><A NAME="ExampleScopeofVariables">

Example: Scope of Variables</A></H3>

<P>

<I>Scope</I> refers to the visibility of variables. In other words,

which parts of your program can see or use it. Normally, every

variable has a global scope. ONCe defined, every part of your

program can access a variable.

<P>

It is very useful to be able to limit a variable's scope to a

single fuNCtion. In other words, the variable wil have a limited

scope. This way, changes inside the fuNCtion can't affect the

main program in unexpected ways. Listing 5.5 introduces two of

Perl's built-in fuNCtions that create variables of limited scope.

The <TT>my()</TT> fuNCtion creates

a variable that only the current fuNCtion can see. The <TT>local()</TT>

fuNCtion creates a variable that fuNCtions the current fuNCtion

calls can see. If that sounds confusing, don't worry. It is confusing;

but, Listing 5.5 should clear things up. In this case, it's a

listing that is worth a thousand words, not a picture!

<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 </I><TT><I>firstSub()</I></TT><I>

with a two parameters.<BR>

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

fuNCtion.<BR>

Assign the first parameter to local variable </I><TT><I>$firstVar</I></TT><I>.

<BR>

Assign the second parameter to my variable </I><TT><I>$secondVar</I></TT><I>.

<BR>

Print the variables.<BR>

Call the second fuNCtion without any parameters.<BR>

Print the variables to see what changed.<BR>

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

fuNCtion.<BR>

Print the variables.<BR>

Assign new values to the variables.<BR>

Print the variables to see that the new values were assigned correctly.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 5.5&nbsp;&nbsp;05LST05.PL-Using the Local and My FuNCtions

to Create Local Variables<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

firstSub(&quot;AAAAA&quot;, &quot;BBBBB&quot;);



sub firstSub{

    local ($firstVar) = $_[0];

    my($secondVar)    = $_[1];



    print(&quot;firstSub: firstVar  = $firstVar\n&quot;);

    print(&quot;firstSub: secondVar = $secondVar\n\n&quot;);



    secondSub();



    print(&quot;firstSub: firstVar  = $firstVar\n&quot;);

    print(&quot;firstSub: secondVar = $secondVar\n\n&quot;);

}



sub secondSub{

    print(&quot;secondSub: firstVar  = $firstVar\n&quot;);

    print(&quot;secondSub: secondVar = $secondVar\n\n&quot;);



    $firstVar  = &quot;ccccC&quot;;

    $secondVar = &quot;DDDDD&quot;;



    print(&quot;secondSub: firstVar  = $firstVar\n&quot;);

    print(&quot;secondSub: secondVar = $secondVar\n\n&quot;);

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

This program prints:

<BLOCKQUOTE>

<PRE>

firstSub: firstVar = AAAAA

firstSub: secondVar = BBBBB



secondSub: firstVar  = AAAAA

Use of uninitialized value at test.pl line 19.

secondSub: secondVar =



secondSub: firstVar  = ccccC

secondSub: secondVar = DDDDD



firstSub: firstVar  = ccccC

firstSub: secondVar = BBBBB

</PRE>

</BLOCKQUOTE>

<P>

The output from this example shows that <TT>secondSub()</TT>

could not access the <TT>$secondVar</TT>

variable that was created with <TT>my()</TT>

inside <TT>firstSub()</TT>. Perl even

prints out an error message that warns about the uninitialized

value. The <TT>$firstVar</TT> variable,

however, can be accessed and valued by <TT>secondSub()</TT>.

<BR>

<p>

<CENTER>

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

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

<TR><TD>

<BLOCKQUOTE>

It's generally a better idea to use <TT>my()</TT> instead of <TT>local()</TT> so that you can tightly control the scope of local variables. Think about it this way-it's 4:00 in the morning and the project is due. Is that the time to be checking variable 
scope? No. Using <TT>my()</TT>enforces good programming practices and reduces headaches.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

Actually, the <TT>my()</TT> fuNCtion

is even more complex than I've said. The easy definition is that

it creates variables that only the current fuNCtion can see. The

true definition is that it creates variables with lexical scope.

This distiNCtion is only important when creating modules or objects,

so let's ignore the complicated definition for now. You'll hear

more about it in <A HREF="ch15.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch15.htm" >Chapter 15</A>, &quot;Perl Modules.&quot;

<P>

If you remember, I mentioned calling parameters by refereNCe.

Passing parameters by refereNCe means that fuNCtions can change

the variable's value, and the main program sees the change. When

<TT>local()</TT> is used in conjuNCtion

with assigning the <TT>@_ </TT>array

elements to scalars, then the parameters are essentially being

called by value. The fuNCtion can change the value of the variable,

but only the fuNCtion is affected. The rest of the program sees

the old value.

<H3><A NAME="ExampleUsingaListasaFuNCtionParameter">

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

<P>

Now that you understand about the scope of variables, let's take

another look at parameters. Because all parameters are passed

to a fuNCtion in one array, what if you need to pass both a scalar

and an array to the same fuNCtion? This next example shows you

what happens.

<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 two parameters: a list and a scalar.<BR>

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

fuNCtion.<BR>

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

array to </I><TT><I>@</I></TT><I>array

and </I><TT><I>$firstVar</I></TT><I>.

<BR>

Print </I><TT><I>@array</I></TT><I>

and </I><TT><I>$firstVar</I></TT><I>.</I>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

firstSub((0..10), &quot;AAAA&quot;);



sub firstSub{

    local(@array, $firstVar) = @_ ;



    print(&quot;firstSub: array    = @array\n&quot;);

    print(&quot;firstSub: firstVar = $firstVar\n&quot;);

}

</PRE>

</BLOCKQUOTE>

<P>

This program prints:

<BLOCKQUOTE>

<PRE>

firstSub: array    = 0 1 2 3 4 5 6 7 8 9 10 AAAA

Use of uninitialized value at test.pl line 8.

firstSub: firstVar =

</PRE>

</BLOCKQUOTE>

<P>

When the local variables are initialized, the <TT>@array</TT>

variables grab all of the elements in the <TT>@</TT>

array, leaving none for the scalar variable. This results in the

uninitialized value message displayed in the output. You can fix

this by merely reversing the order of parameters. If the scalar

value comes first, then the fuNCtion processes the parameters

without a problem.

<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 two parameters: a scalar and a list.<BR>

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

fuNCtion.<BR>

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

array to </I><TT><I>$firstVar</I></TT><I>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
蜜桃久久av一区| 国产精品传媒视频| 久久女同性恋中文字幕| 亚洲国产精品成人综合| 一区二区日韩av| 日本伊人色综合网| 国产乱一区二区| 国产成人精品免费| 欧洲视频一区二区| 日韩免费一区二区| 亚洲欧洲国产日本综合| 三级精品在线观看| 国产成人aaa| 欧美日韩高清一区二区不卡| 精品久久久久久久久久久院品网| 国产精品乱码妇女bbbb| 亚洲亚洲人成综合网络| 国产一区二区在线视频| 色综合一区二区| 日韩精品专区在线| 亚洲欧美在线另类| 九九久久精品视频| 在线看日韩精品电影| 久久久精品免费观看| 亚洲一级二级在线| 国产精品自拍一区| 在线欧美小视频| 精品国精品国产尤物美女| 亚洲激情中文1区| 国产一区欧美一区| 69堂亚洲精品首页| 中文字幕亚洲精品在线观看| 另类综合日韩欧美亚洲| 色哟哟一区二区在线观看| 精品国产欧美一区二区| 一区二区成人在线观看| 国产99久久久精品| 欧美一区二区三区日韩视频| 亚洲欧美日韩综合aⅴ视频| 韩国成人福利片在线播放| 欧美日韩国产综合一区二区| 日韩一区中文字幕| 国产精品影视天天线| 3atv一区二区三区| 亚洲美女视频在线观看| 成人在线综合网站| 欧美成人一区二区三区| 午夜一区二区三区视频| 91丝袜国产在线播放| 国产欧美综合在线观看第十页| 视频一区视频二区在线观看| 91久色porny | 欧美日韩国产一级二级| 国产精品免费视频一区| 国产在线看一区| 91精品福利在线一区二区三区 | 不卡的看片网站| 久久亚洲综合av| 男男gaygay亚洲| 欧美亚洲禁片免费| 亚洲欧洲av一区二区三区久久| 国产精品羞羞答答xxdd| 久久综合五月天婷婷伊人| 奇米影视一区二区三区小说| 538prom精品视频线放| 午夜不卡av在线| 欧美日韩aaaaaa| 亚洲小说春色综合另类电影| 精品视频123区在线观看| 亚洲精品乱码久久久久| 色综合久久精品| 亚洲欧美激情视频在线观看一区二区三区| 成人在线综合网站| 亚洲欧洲日韩一区二区三区| av一区二区不卡| 亚洲欧洲色图综合| 色欧美片视频在线观看| 亚洲精品ww久久久久久p站| 91亚洲资源网| 一区二区三区在线观看网站| 欧美性大战久久久久久久 | 欧美日韩电影在线播放| 亚洲大尺度视频在线观看| 欧美日韩久久久| 天天综合天天做天天综合| 在线播放亚洲一区| 蜜臀av性久久久久蜜臀aⅴ流畅 | 捆绑紧缚一区二区三区视频| 日韩欧美一区二区不卡| 国产一区二区三区在线观看免费视频 | 久久久久久久久久久久久久久99 | 国产女同性恋一区二区| 不卡的av中国片| 亚洲理论在线观看| 欧美日韩亚洲综合一区二区三区 | 精品国产一区二区三区av性色| 国产在线视频一区二区三区| 国产精品三级在线观看| 91蝌蚪porny成人天涯| 午夜精品在线视频一区| 日韩女优电影在线观看| 国产成人夜色高潮福利影视| 中文字幕在线不卡一区二区三区| 一本大道久久精品懂色aⅴ| 午夜亚洲国产au精品一区二区| 精品国产免费一区二区三区四区| 丰满放荡岳乱妇91ww| 一区二区三区在线观看视频| 日韩午夜激情电影| 国产一区二区三区| 亚洲免费观看高清在线观看| 777久久久精品| 成人精品鲁一区一区二区| 亚洲一区二区美女| 欧美大片顶级少妇| av不卡一区二区三区| 视频在线观看一区| 国产精品毛片大码女人| 欧美日韩一级大片网址| 国产激情视频一区二区三区欧美| 亚洲激情六月丁香| 精品国产乱码久久久久久图片 | 亚洲欧美另类久久久精品| 91 com成人网| 成人一道本在线| 午夜欧美一区二区三区在线播放| 久久久高清一区二区三区| 在线视频一区二区免费| 国产麻豆精品theporn| 亚洲一区二区三区在线| 久久久不卡网国产精品一区| 欧美在线999| 国产福利一区二区三区视频| 亚洲高清久久久| 中文字幕av在线一区二区三区| 欧美日韩欧美一区二区| 成人高清视频在线| 日本中文字幕不卡| 亚洲黄一区二区三区| 久久久久久久久久久久久久久99| 欧美日韩亚洲丝袜制服| 99热在这里有精品免费| 老司机免费视频一区二区三区| 一区二区在线看| 国产欧美精品区一区二区三区 | 国内精品不卡在线| 亚洲国产aⅴ成人精品无吗| 日本一区二区三区国色天香| 日韩一区二区在线观看视频播放| 色激情天天射综合网| 大白屁股一区二区视频| 久久97超碰色| 亚洲国产成人va在线观看天堂| 最近日韩中文字幕| 国产亚洲精品aa午夜观看| 日韩一区二区三区电影在线观看| 色婷婷综合久久久中文字幕| 成人午夜碰碰视频| 精品一区二区三区免费毛片爱| 日日摸夜夜添夜夜添亚洲女人| 亚洲人成网站在线| 国产精品久久久久影院亚瑟| 久久这里只有精品首页| 日韩欧美成人一区| 欧美一区二区三区四区视频| 欧美日韩中文国产| 日本高清不卡在线观看| 91麻豆免费看片| 99国产精品国产精品久久| 国产成人日日夜夜| 精品亚洲成a人在线观看 | 久久精品男人天堂av| 日韩免费观看高清完整版| 欧美日韩aaaaa| 欧美精品xxxxbbbb| 欧美精品色综合| 欧美日韩一区久久| 欧美日韩国产片| 欧美网站一区二区| 欧美日韩五月天| 欧美日韩一区二区欧美激情| 欧美性大战久久久久久久蜜臀 | 免费人成黄页网站在线一区二区| 性做久久久久久免费观看欧美| 一卡二卡三卡日韩欧美| 亚洲在线成人精品| 亚洲福利一区二区| 日日夜夜免费精品视频| 蜜臀久久久99精品久久久久久| 蜜桃av噜噜一区| 精品一区二区av| 国产成人高清视频| 波多野结衣中文字幕一区二区三区| 成人综合婷婷国产精品久久蜜臀| av一区二区三区在线| 色综合久久88色综合天天6 | 捆绑调教美女网站视频一区| 狠狠色狠狠色综合系列| 国产91丝袜在线播放0| www.欧美日韩|