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

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

?? ch9.htm

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

The <TT>open()</TT> fuNCtion has many

variations to let you access files in different ways. Table 9.4

shows all of the different methods used to open a file.<BR>

<P>

<CENTER><B>Table 9.4&nbsp;&nbsp;The Different Ways to Open a File</B></CENTER>

<p>

<CENTER>

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

<TR><TD WIDTH=175><I>Open Statement</I></TD><TD WIDTH=415><I>Description</I>

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>);

</TD><TD WIDTH=415>Opens the file named in <TT>$FILE_HANDLE</TT> and connect to it using <TT>FILE_HANDLE</TT> as the file handle. The file will be opened for input only.

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>FILENAME.EXT</I></TT>);

</TD><TD WIDTH=415>Opens the file called <TT><I>FILENAME.EXT</I></TT> for input using  <TT>FILE_HANDLE</TT> as the file handle.

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, +<TT><I>&lt;FILENAME.EXT</I></TT>);

</TD><TD WIDTH=415>Opens <TT><I>FILENAME.EXT</I></TT> for input using <TT>FILE_HANDLE</TT> as the file handle.

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>&gt;FILENAME.EXT</I></TT>);

</TD><TD WIDTH=415>Opens <TT><I>FILENAME.EXT</I></TT> for output using <TT>FILE_HANDLE</TT> as  the file handle.

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>-</I></TT>);

</TD><TD WIDTH=415>Opens standard input.</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>&gt;-</I></TT>);

</TD><TD WIDTH=415>Opens standard output.</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>&gt;&gt;FILENAME.EXT</I></TT>);

</TD><TD WIDTH=415>Opens <TT><I>FILENAME.EXT</I></TT> for appending using <TT>FILE_HANDLE</TT> as the file handle.

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>+&lt;FILENAME.EXT</I></TT>);

</TD><TD WIDTH=415>Opens <TT><I>FILENAME.EXT</I></TT> for both input and output using <TT>FILE_HANDLE</TT> as the file handle.

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>+&gt;FILENAME.EXT</I></TT>);

</TD><TD WIDTH=415>Opens <TT><I>FILENAME.EXT</I></TT> for both input and output using <TT>FILE_HANDLE</TT> as the file handle.

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>+&gt;&gt;FILENAME.EXT</I></TT>);

</TD><TD WIDTH=415>Opens <TT><I>FILENAME.EXT</I></TT> for both input and output using <TT>FILE_HANDLE</TT> as the file handle.

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>| PROGRAM</I></TT>)

</TD><TD WIDTH=415>Sends the output printed to <TT>FILE_HANDLE</TT> to another program.

</TD></TR>

<TR><TD WIDTH=175><TT>open</TT>(<TT>FILE_HANDLE</TT>, <TT><I>PROGRAM |</I></TT>)

</TD><TD WIDTH=415>Reads the output from another program using  <TT>FILE_HANDLE</TT>.

</TD></TR>

</TABLE>

</CENTER>

<P>

<p>

<CENTER>

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

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

<TR><TD>

<BLOCKQUOTE>

I am currently researching the differeNCes between +&lt;, +&gt;, and +&gt;&gt;. The research should be available by 12/1/97 as a link from </BLOCKQUOTE>

<BLOCKQUOTE>

<TT>http:\\www.mtolive.com\pbe\index.html.</TT>

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

For information about handling failures while opening files, see

<A HREF="ch13.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch13.htm" >Chapter 13</A>, &quot;Handling Errors and Signals.&quot; 

<P>

By prefixing the file name with a &gt; character you open the

file for output. This next example opens a file that will hold

a log of messages.

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

fuNCtion to open the </I><TT><I>MESSAGE.LOG</I></TT><I>

file for writing with </I><TT><I>LOGFILE</I></TT><I>

as the file handle. If the open was successful, a true value will

be returned and the statement block will be executed.<BR>

Send the first message to the </I><TT><I>MESSAGE.LOG</I></TT><I>

file using the </I><TT><I>print()</I></TT><I>

fuNCtion. Notice that an alternate method is being used to call

</I><TT><I>print()</I></TT><I>.<BR>

Send the second message to the </I><TT><I>MESSAGE.LOG</I></TT><I>

file.<BR>

Close the file.</I>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

if (open(LOGFILE, &quot;&gt;message.log&quot;)) {

    print LOGFILE (&quot;This is message number 1.\n&quot;);

    print LOGFILE (&quot;This is message number 2.\n&quot;);

    close(LOGFILE);

}

</PRE>

</BLOCKQUOTE>

<P>

This program displays nothing. Instead, the output from the <TT>print()</TT>

fuNCtion is sent directly to the <TT>MESSAGE.LOG</TT>

file using the connection established by the <TT>open()</TT>

fuNCtion.

<P>

In this example, the <TT>print()</TT>

fuNCtion uses the first parameter as a file handle and the second

parameter as a list of things to print. You can find more information

about printing in the section, &quot;Example: Printing Revisited,&quot;

later in this chapter.

<P>

If you needed to add something to the end of the MESSAGE.LOG file,

you use <TT>&gt;&gt;</TT> as the file

name prefix when opening the file. For example:

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

fuNCtion to open the </I><TT><I>MESSAGE.LOG</I></TT><I>

file for appending with </I><TT><I>LOGFILE</I></TT><I>

as the file handle. If the file does not exist, it will be created;

otherwise, anything printed to </I><TT><I>LOGFILE</I></TT><I>

will be added to the end of the file.<BR>

Send a message to the </I><TT><I>MESSAGE.LOG</I></TT><I>

file.<BR>

Send a message to the </I><TT><I>MESSAGE.LOG</I></TT><I>

file.<BR>

Close the file.</I>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

if (open(LOGFILE, &quot;&gt;&gt;message.log&quot;)) {

    print LOGFILE (&quot;This is message number 3.\n&quot;);

    print LOGFILE (&quot;This is message number 4.\n&quot;);

    close(LOGFILE);

}

</PRE>

</BLOCKQUOTE>

<P>

Now, when <TT>MESSAGE.LOG</TT> is

viewed, it contains the following lines:

<BLOCKQUOTE>

<PRE>

This is message number 1.

This is message number 2.

This is message number 3.

This is message number 4.

</PRE>

</BLOCKQUOTE>

<H3><A NAME="ExampleBinaryFiles">

Example: Binary Files</A></H3>

<P>

When you need to work with data files, you will need to know what

binary mode is. There are two major differeNCes between binary

mode and text mode:

<UL>

<LI>In DOS and Windows, line endings are indicated by two characters-the

newline and carriage return characters. When in text mode, these

characters are input as a single character, the newline character.

In binary mode, both characters can be read by your program. UNIX

systems only use one character, the newline, to indicate line

endings.

<LI>In DOS and Windows, the end of file character is 26. When

a byte with this value is read in text mode, the file is considered

ended and your program cannot read any more information from the

file. UNIX considers the end-of-file character to be 4. For both

operating systems, binary mode will let the end-of-file character

be treated as a regular character.

</UL>

<P>

<p>

<CENTER>

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

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

<TR><TD>

<BLOCKQUOTE>

The examples in this section relate to the DOS operating system.</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

In order to demonstrate these differeNCes, we'll use a data file

called BINARY.DAT with the following contents:

<BLOCKQUOTE>

<PRE>

01

02

03

</PRE>

</BLOCKQUOTE>

<P>

First, we'll read the file in the default text mode.

<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>Initialize a buffer variable. Both </I><TT><I>read()</I></TT><I>

and </I><TT><I>sysread()</I></TT><I>

need their buffer variables to be initialized before the fuNCtion

call is executed.<BR>

Open the </I><TT><I>BINARY.DAT</I></TT><I>

file for reading.<BR>

Read the first 20 characters of the file using the </I><TT><I>read()</I></TT><I>

fuNCtion.<BR>

Close the file.<BR>

Create an array out of the characters in the </I><TT><I>$buffer</I></TT><I>

variable and iterate over that array using a </I><TT><I>foreach</I></TT><I>

loop.<BR>

Print the value of the current array element in hexadecimal format.

<BR>

Print a newline character. The current array element is a newline

character.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 9.8&nbsp;&nbsp;09LST08.PL-Reading a File to Show Text

Mode Line Endings<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

$buffer = &quot;&quot;;



open(FILE, &quot;&gt;binary.dat&quot;);

read(FILE, $buffer, 20, 0);

close(FILE);



foreach (split(//, $buffer)) {

    printf(&quot;%02x &quot;, ord($_));

    print &quot;\n&quot; if $_ eq &quot;\n&quot;;

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

This program displays:

<BLOCKQUOTE>

<PRE>

30 31 0a

30 32 0a

30 33 0a

</PRE>

</BLOCKQUOTE>

<P>

This example does a couple of things that haven't been seen yet

in this book. The <TT>Read()</TT>

fuNCtion is used as an alternative to the line-by-line input done

with the diamond operator. It will read a specified number of

bytes from the input file and assign them to a buffer variable.

The fourth parameter specifies an offset at which to start reading.

In this example, we started at the beginning of the file.

<P>

The <TT>split()</TT> fuNCtion in the

<TT>foreach</TT> loop breaks a string

into pieces and places those pieces into an array. The double

slashes indicate that each character in the string should be an

element of the new array. 

<P>

For more information about the <TT>split()</TT>

fuNCtion, see <A HREF="ch5.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch5.htm" >Chapter 5</A> &quot;FuNCtions,&quot; and <A HREF="ch10.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch10.htm" >Chapter 10</A>,

&quot;Regular Expressions.&quot; 

<P>

ONCe the array of characters has been created, the <TT>foreach</TT>

loop iterates over the array. The <TT>printf()</TT>

statement converts the ordinal value of the character into hexadecimal

before displaying it. The <I>ordinal</I> value of a character

is the value of the ASCII representation of the character. For

example, the ordinal value of '0' is 0x30 or 48.

<P>

The next line, the print statement, forces the output onto a new

line if the current character is a newline character. This was

done simply to make the output display look a little like the

input file. 

<P>

For more information about the <TT>printf()</TT>

fuNCtion, see the section, &quot;Example: Printing Revisited,&quot;

later in this chapter.

<P>

Now, let's read the file in binary mode and see how the output

is changed.

<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>Initialize a buffer variable.<BR>

Open the </I><TT><I>BINARY.DAT</I></TT><I>

file for reading.<BR>

Change the mode to binary.<BR>

Read the first 20 characters of the file using the </I><TT><I>read()</I></TT><I>

fuNCtion.<BR>

Close the file.<BR>

Create an array out of the characters in the </I><TT><I>$buffer</I></TT><I>

variable and iterate over that array using a </I><TT><I>foreach</I></TT><I>

loop.<BR>

Print the value of the current array element in hexadecimal format.

<BR>

Print a newline character. The current array element is a newline

character.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 9.9&nbsp;&nbsp;09LST09.PL-Reading a File to Show Binary

Mode Line Endings<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

$buffer = &quot;&quot;;



open(FILE, &quot;&lt;binary.dat&quot;);

binmode(FILE); 

read(FILE, $buffer, 20, 0);

close(FILE);



foreach (split(//, $buffer)) {

    printf(&quot;%02x &quot;, ord($_));

    print &quot;\n&quot; if $_ eq &quot;\n&quot;;

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美最猛性xxxxx直播| 日本成人在线一区| 97se狠狠狠综合亚洲狠狠| 国产欧美日韩在线观看| 高清国产一区二区三区| 亚洲三级视频在线观看| 欧美吞精做爰啪啪高潮| 男人的天堂亚洲一区| 久久亚洲精品国产精品紫薇| 不卡电影一区二区三区| 一个色妞综合视频在线观看| 在线不卡中文字幕播放| 精品系列免费在线观看| 中文字幕国产一区| 在线观看日韩av先锋影音电影院| 青青国产91久久久久久| 国产欧美精品一区aⅴ影院 | 麻豆91在线看| 久久久久综合网| 色婷婷亚洲精品| 蜜臀av性久久久久蜜臀aⅴ流畅 | 久久久99免费| www.av亚洲| 日韩影院在线观看| 国产色产综合色产在线视频| 色婷婷国产精品| 国产在线观看一区二区| 日韩码欧中文字| xnxx国产精品| 欧美日韩国产一级| 成人免费毛片嘿嘿连载视频| 日韩精品免费专区| 国产精品免费久久久久| 91精品国产综合久久精品性色 | 国产日产精品1区| 欧美影院精品一区| 成人午夜私人影院| 蜜臀a∨国产成人精品| 亚洲美女在线一区| 国产亚洲精品7777| 日韩欧美亚洲国产另类| 色婷婷久久综合| 成人精品在线视频观看| 久久精品国产亚洲一区二区三区| 亚洲在线中文字幕| 中文字幕av不卡| 精品美女一区二区| 欧美美女直播网站| 91电影在线观看| 成人av网站在线| 国产一区二区三区久久久| 免费在线观看日韩欧美| 亚洲国产裸拍裸体视频在线观看乱了 | 国产精品沙发午睡系列990531| 日韩一级免费观看| 欧美日韩日日摸| 色综合久久66| 91在线国产福利| 成人av免费在线播放| 极品销魂美女一区二区三区| 日韩在线一二三区| 午夜精品123| 天天av天天翘天天综合网色鬼国产| 综合中文字幕亚洲| 国产精品久久久久一区二区三区 | 国产乱码精品一区二区三区av | 国产成人99久久亚洲综合精品| 免费观看一级特黄欧美大片| 亚洲一区二区黄色| 亚洲色图欧美偷拍| 亚洲欧美偷拍卡通变态| 亚洲色图欧美激情| 一区二区三区日韩在线观看| 亚洲精品日韩专区silk| 一区二区三区国产| 亚洲线精品一区二区三区| 亚洲在线视频网站| 五月婷婷久久综合| 蜜臀精品一区二区三区在线观看| 麻豆专区一区二区三区四区五区| 欧美aaa在线| 久久精品国产亚洲高清剧情介绍| 美女视频一区二区三区| 国精产品一区一区三区mba视频| 国产一区二区三区四区五区入口 | 三级不卡在线观看| 麻豆91精品91久久久的内涵| 久久狠狠亚洲综合| 国产成人h网站| 97aⅴ精品视频一二三区| 91麻豆精东视频| 欧洲亚洲精品在线| 欧美欧美欧美欧美首页| 欧美精品一区二区在线播放| 久久精品夜色噜噜亚洲aⅴ| 亚洲欧洲另类国产综合| 一区二区三区欧美久久| 日韩高清一区二区| 国产老妇另类xxxxx| 91网站最新地址| 欧美日本免费一区二区三区| 久久婷婷国产综合国色天香| 中文字幕久久午夜不卡| 一区二区三区中文在线| 日本亚洲一区二区| 成人天堂资源www在线| 欧美亚洲一区二区在线| 欧美mv和日韩mv的网站| 亚洲欧洲国产专区| 图片区小说区区亚洲影院| 国产精品一卡二卡| 欧美手机在线视频| 国产欧美一区二区精品性色超碰| 亚洲一区二区三区三| 麻豆国产精品一区二区三区| av不卡免费电影| 欧美一区二区成人| 成人欧美一区二区三区黑人麻豆 | 99久久精品费精品国产一区二区| 欧美美女bb生活片| 国产女人18水真多18精品一级做 | 欧美无砖专区一中文字| 久久综合色天天久久综合图片| 最近日韩中文字幕| 国内精品嫩模私拍在线| 欧美亚洲高清一区| 国产午夜久久久久| 日本成人在线不卡视频| 91在线精品一区二区| xnxx国产精品| 日av在线不卡| 色综合亚洲欧洲| 国产拍揄自揄精品视频麻豆| 免费视频一区二区| 欧洲人成人精品| 国产欧美日韩另类一区| 久久激情综合网| 欧美精品一卡两卡| 一区二区三区视频在线观看| 成人av午夜电影| 国产亚洲精品资源在线26u| 美腿丝袜在线亚洲一区| 欧美日韩一区视频| 最新日韩在线视频| 成人网在线播放| 国产日韩欧美不卡| 国内精品在线播放| 欧美哺乳videos| 亚洲成人高清在线| 欧美亚洲一区二区三区四区| 亚洲免费av高清| 色婷婷亚洲综合| 综合精品久久久| 99久久免费国产| 国产精品护士白丝一区av| 国产成人精品影院| 久久久精品中文字幕麻豆发布| 久久99精品一区二区三区| 欧美另类videos死尸| 亚洲gay无套男同| 欧美视频一区二区在线观看| 亚洲综合免费观看高清完整版 | 久久久亚洲精品石原莉奈| 蜜臀久久久久久久| 欧美大片在线观看一区| 久久国产生活片100| 欧美成人伊人久久综合网| 麻豆91在线观看| www成人在线观看| 国产美女精品人人做人人爽| 久久无码av三级| 成人听书哪个软件好| 国产精品乱码久久久久久| av亚洲精华国产精华精| 亚洲美女免费视频| 91黄视频在线| 日韩精品福利网| 精品精品国产高清a毛片牛牛| 国内一区二区视频| 中文字幕精品一区二区精品绿巨人| 成人性生交大片免费看中文| 亚洲欧洲av在线| 91成人在线观看喷潮| 日韩在线观看一区二区| 久久综合久久综合亚洲| 国产一区二区在线免费观看| 久久精品亚洲一区二区三区浴池 | 中文字幕精品—区二区四季| 99精品视频一区| 亚洲国产综合91精品麻豆| 91精品国产综合久久久久久漫画| 激情国产一区二区| 国产精品女同一区二区三区| 在线观看日韩国产| 久久99精品久久久久久动态图 | 欧美亚洲禁片免费| 奇米精品一区二区三区在线观看 | 婷婷中文字幕一区三区| 精品国产一区二区三区久久影院 | 岛国精品在线观看|