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

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

?? ch9.htm

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

<HEAD>

<TITLE>Chapter 9 -- Using Files</TITLE>



<META>

</HEAD>

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

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

<H1><FONT SIZE=6 COLOR=#FF0000>Using Files</FONT></H1>

<HR>

<P>

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

<UL>

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

Some Files Are Standard</A>

<UL>

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

Example: Using STDIN</A>

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

Example: Using Redirection to Change STDIN and STDOUT</A>

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

Example: Using the Diamond Operator (&lt;&gt;)</A>

</UL>

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

File Test Operators</A>

<UL>

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

Example: Using File Tests</A>

</UL>

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

File FuNCtions<BR>

</A>

<UL>

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

Example: Opening Files</A>

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

Example: Binary Files</A>

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

Example: Getting File Statistics</A>

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

Example: Using the Directory FuNCtions</A>

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

Example: Printing Revisited</A>

</UL>

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

Globbing</A>

<UL>

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

Example: Assigning a Glob to an Array</A>

</UL>

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

Using Data Structures with Files</A>

<UL>

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

Example: Splitting a Record into Fields</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>

If you've read the previous chapters and have executed some of

the programs, then you already know that a file is a series of

bytes stored on a disk instead of inside the computer's memory.

A <I>file</I> is good for long-term storage of information. Information

in the computer's memory is lost when the computer is turned off.

Information on a disk, however, is persistent. It will be there

when the computer is turned back on.

<P>

Back in <A HREF="ch1.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch1.htm" >Chapter 1</A> &quot;Getting Your Feet Wet,&quot; you saw

how to create a file using the edit program that comes with Windows

95 and Windows NT. In this chapter, you'll see how to manipulate

files with Perl.

<P>

There are four basic operations that you can do with files. You

can open them, read from them, write to them, and close them.

Opening a file creates a connection between your program and the

location on the disk where the file is stored. Closing a file

shuts down that connection.

<P>

Every file has a unique <I>fully qualified </I>name so that it

can't be confused with other files. The fully qualified name iNCludes

the name of the disk, the directory, and the file name. Files

in different directories can have the same name because the operating

system considers the directory name to be a part of the file name.

Here are some fully qualified file names:

<BLOCKQUOTE>

<PRE>

c:/windows/win95.txt

c:/windows/command/scandisk.ini

c:/a_long_directory_name/a_long_subdirectory_name/a_long_file_name.doc

<BR>



</PRE>

</BLOCKQUOTE>

<p>

<CENTER>

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

<TR><TD><B>Caution</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

You may be curious to know if spaces can be used inside file names. Yes, they can. But, if you use spaces, you need to surround the file name with quotes when referring to it from a DOS or UNIX command line.</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>

It is very important that you check for errors when dealing with files. To simplify the examples in this chapter, little error checking will be used in the example. Instead, error checking information will be discussed in <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;</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<H2><A NAME="SomeFilesAreStandard"><FONT SIZE=5 COLOR=#FF0000>

Some Files Are Standard</FONT></A></H2>

<P>

In an effort to make programs more uniform, there are three connections

that always exist when your program starts. These are <TT>STDIN</TT>,

<TT>STDOUT</TT>, and <TT>STDERR</TT>.

Actually, these names are <I>file handles</I>. File handles are

variables used to manipulate files. Just like you need to grab

the handle of a hot pot before you can pick it up, you need a

file handle before you can use a file. Table 9.1 describes the

three file handles.<BR>

<P>

<CENTER><B>Table 9.1&nbsp;&nbsp;The Standard File Handles</B></CENTER>

<p>

<CENTER>

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

<TR><TD WIDTH=73><I>Name</I></TD><TD WIDTH=517><I>Description</I>

</TD></TR>

<TR><TD WIDTH=73><TT>STDIN</TT></TD>

<TD WIDTH=517>Reads program input. Typically this is the computer's keyboard.

</TD></TR>

<TR><TD WIDTH=73><TT>STDOUT</TT></TD>

<TD WIDTH=517>Displays program output. This is usually the computer's monitor.

</TD></TR>

<TR><TD WIDTH=73><TT>STDERR</TT></TD>

<TD WIDTH=517>Displays program errors. Most of the time, it is equivalent to <TT>STDOUT</TT>, which means the error messages will be displayed on the computer's monitor.

</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

You've been using the <TT>STDOUT</TT>

file handle without knowing it for every <TT>print()</TT>

statement in this book. The <TT>print()</TT>

fuNCtion uses <TT>STDOUT</TT> as the

default if no other file handle is specified. Later in this chapter,

in the &quot;Examples: Printing Revisited&quot; section, you will

see how to send output to a file instead of to the monitor.

<H3><A NAME="ExampleUsingSTDIN">

Example: Using STDIN</A></H3>

<P>

Reading a line of input from the standard input, <TT>STDIN</TT>,

is one of the easiest things that you can do in Perl. This following

three-line program will read a line from the keyboard and then

display it. This will continue until you press <TT>Ctrl+Z</TT>

on DOS systems or <TT>Ctrl-D</TT>

on UNIX systems.

<HR>

<BLOCKQUOTE>

<B>Listing 9.1&nbsp;&nbsp;09LST01.PL-Read from Standard Input

Until an End-of-File Character Is Found<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

while (&lt;STDIN&gt;) {

    print();

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

The <TT>&lt;&gt;</TT> characters,

when used together, are called the <I>diamond</I> operator. It

tells Perl to read a line of input from the file handle inside

the operator. In this case, <TT>STDIN</TT>.

Later, you'll use the diamond operator to read from other file

handles.

<P>

In this example, the diamond operator assigned the value of the

input string to <TT>$_ </TT>. Then,

the <TT>print()</TT> fuNCtion was

called with no parameters, which tells <TT>print()</TT>

to use <TT>$_</TT> as the default

parameter. Using the <TT>$_ </TT>

variable can save a lot of typing, but I'll let you decide which

is more readable. Here is the same program without using <TT>$_</TT>.

<BLOCKQUOTE>

<PRE>

while ($inputLine = &lt;STDIN&gt;) {

    print($inputLine);

}

</PRE>

</BLOCKQUOTE>

<P>

When you pressed <TT>Ctrl+Z</TT> or

<TT>Ctrl+D</TT>, you told Perl that

the input file was finished. This caused the diamond operator

to return the undefined value which Perl equates to false and

caused the <TT>while</TT> loop to

end. In DOS (and therefore in all of the flavors of Windows),

26-the value of <TT>Ctrl+Z</TT>-is

considered to be the end-of-file indicator. As DOS reads or writes

a file, it monitors the data stream and when a value of 26 is

eNCountered the file is closed. UNIX does the same thing when

a value of 4-the value of <TT>Ctrl+D</TT>-is

read.<BR>

<p>

<CENTER>

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

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

<TR><TD>

<BLOCKQUOTE>

When a file is read using the diamond operator, the newline character that ends the line is kept as part of the input string. Frequently, you'll see the <TT>chop()</TT> fuNCtion used to remove the newline. For instaNCe, <TT>chop($inputLine = 
&lt;INPUT_FILE&gt;);</TT>. This statement reads a line from the input file, assigns its value to <TT>$inputLine</TT> and then removes that last character from <TT>$inputLine</TT>-which is almost guaranteed to be a newline character. If you fear that the 
last character is not a newline, use the <TT>chomp()</TT> fuNCtion instead.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<H3><A NAME="ExampleUsingRedirectiontoChangeSTDINandSTDOUT">

Example: Using Redirection to Change STDIN and STDOUT</A></H3>

<P>

DOS and UNIX let you change the standard input from being the

keyboard to being a file by changing the command line that you

use to execute Perl programs. Until now, you probably used a command

line similar to:

<BLOCKQUOTE>

<PRE>

perl -w 09lst01.pl

</PRE>

</BLOCKQUOTE>

<P>

In the previous example, Perl read the keyboard to get the standard

input. But, if there was a way to tell Perl to use the file <TT>09LST01.PL</TT>

as the standard input, you could have the program print itself.

Pretty neat, huh? Well, it turns out that you can change the standard

input. It's done this way:

<BLOCKQUOTE>

<PRE>

perl -w 09lst01.pl &lt; 09lst01.pl

</PRE>

</BLOCKQUOTE>

<P>

The &lt; character is used to <I>redirect</I> the standard input

to the 09LST01.PL file. You now have a program that duplicates

the fuNCtionality of the DOS type command. And it only took three

lines of Perl code!

<P>

You can redirect standard output to a file using the <TT>&gt;</TT>

character. So, if you wanted a copy of <TT>09LST01.PL</TT>

to be sent to <TT>OUTPUT.LOG,</TT>

you could use this command line:

<BLOCKQUOTE>

<PRE>

perl -w 09lst01.pl &lt;09lst01.pl &gt;output.log

</PRE>

</BLOCKQUOTE>

<P>

Keep this use of the <TT>&lt;</TT>

and <TT>&gt;</TT> characters in mind.

You'll be using them again shortly when we talk about the <TT>open()</TT>

fuNCtion. The <TT>&lt;</TT> character

will signify that files should be opened for input and the <TT>&gt;</TT>

will be used to signify an output file. But first, let's continue

talking about accessing files listed on the command line.

<H3><A NAME="ExampleUsingtheDiamondOperatorltgt">

Example: Using the Diamond Operator (&lt;&gt;)</A></H3>

<P>

If no file handle is used with the diamond operator, Perl will

examine the <TT>@ARGV</TT> special

variable. If <TT>@ARGV</TT> has no

elements, then the diamond operator will read from <TT>STDIN</TT>-either

from the keyboard or from a redirected file. So, if you wanted

to display the contents of more than one file, you could use the

program shown in Listing 9.2.

<HR>

<BLOCKQUOTE>

<B>Listing 9.2&nbsp;&nbsp;09LST02.PL-Read from Multiple Files

or from </B><TT><I><B><FONT FACE="Courier">STDIN<BR>

</FONT></B></I></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

while (&lt;&gt;) {

    print();

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

The command line to run the program might look like this:

<BLOCKQUOTE>

<PRE>

perl -w 09lst02.pl 09lst01.pl 09lst02.pl

</PRE>

</BLOCKQUOTE>

<P>

And the output would be:

<BLOCKQUOTE>

<PRE>

while (&lt;STDIN&gt;) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美午夜宅男影院| 中文字幕高清不卡| 国产欧美va欧美不卡在线| 国产精品久久久久一区二区三区| 香蕉影视欧美成人| av在线一区二区三区| 欧美一二三区在线观看| 一区二区三区在线观看欧美 | 欧美tickling网站挠脚心| 国产精品白丝在线| 国模一区二区三区白浆| 欧美日韩国产一区二区三区地区| 国产欧美精品区一区二区三区| 五月综合激情日本mⅴ| 不卡视频在线观看| 国产日韩欧美不卡在线| 久久er99精品| 欧美一区二区视频免费观看| 一区二区三区在线观看视频 | 国产福利精品一区| 日韩天堂在线观看| 偷拍与自拍一区| 色综合久久久久综合99| 国产精品美女www爽爽爽| 国产麻豆精品一区二区| 欧美成人a∨高清免费观看| 日韩av中文字幕一区二区| 91久久线看在观草草青青| 中文字幕日韩av资源站| kk眼镜猥琐国模调教系列一区二区 | 6080yy午夜一二三区久久| 亚洲自拍都市欧美小说| 在线观看日韩毛片| 亚洲国产精品欧美一二99| 91美女片黄在线观看| 一区二区三区四区精品在线视频 | 国产精品18久久久久久久网站| 日韩欧美电影一区| 韩国精品免费视频| 国产亚洲人成网站| 成人蜜臀av电影| 中文字幕字幕中文在线中不卡视频| 91蝌蚪国产九色| 亚洲综合av网| 日韩欧美色综合网站| 麻豆免费精品视频| 国产亚洲欧美色| proumb性欧美在线观看| 亚洲一区二区av在线| 欧美一区二区三区小说| 免费看欧美女人艹b| 欧美精品一区二区三区视频| 国产99久久久国产精品潘金| 成人免费一区二区三区在线观看 | 亚洲国产精品久久一线不卡| 91.xcao| 国产精品一区久久久久| 中文字幕av一区 二区| 色综合天天性综合| 免费成人在线观看| 中文字幕不卡三区| 欧美三级三级三级爽爽爽| 蜜臀99久久精品久久久久久软件| 国产女主播视频一区二区| 91在线丨porny丨国产| 日韩va亚洲va欧美va久久| 久久久亚洲精品石原莉奈| 色伊人久久综合中文字幕| 日精品一区二区| 国产精品天美传媒| 欧美性大战xxxxx久久久| 麻豆精品一二三| 亚洲精品免费在线| 欧美xxxx老人做受| 91国产免费观看| 国产精品一色哟哟哟| 夜夜精品浪潮av一区二区三区| 欧美一区二区三区影视| 色女孩综合影院| 黄色资源网久久资源365| 又紧又大又爽精品一区二区| 久久久99久久| 欧美顶级少妇做爰| 91视频国产资源| 精品综合免费视频观看| 亚洲制服丝袜一区| 国产精品成人在线观看| 日韩精品一区在线| 在线观看av一区二区| 成年人国产精品| 国产成人免费网站| 蜜桃传媒麻豆第一区在线观看| 亚洲精品一二三区| 日韩伦理电影网| 欧美—级在线免费片| 精品精品欲导航| 欧美日本国产视频| 99精品国产视频| 成人综合婷婷国产精品久久免费| 免费一级片91| 日本91福利区| 三级一区在线视频先锋| 亚洲免费毛片网站| 国产精品少妇自拍| 日本一区二区三区免费乱视频 | 欧美剧情片在线观看| 91福利视频网站| 99精品久久99久久久久| 99久久精品国产一区| 成人免费毛片片v| 白白色亚洲国产精品| 国产激情精品久久久第一区二区| 麻豆精品在线观看| 国产在线国偷精品免费看| 麻豆一区二区三| 国产精一品亚洲二区在线视频| 久久er精品视频| 国产精品自拍在线| 国产成人亚洲综合a∨婷婷| 国产麻豆精品久久一二三| 国产综合色视频| 国产精品888| 99久久精品国产毛片| 91麻豆精品秘密| 欧美色欧美亚洲另类二区| 欧美裸体一区二区三区| 欧美一区二区视频网站| 欧美成人video| 亚洲国产成人私人影院tom| 中文字幕在线播放不卡一区| 亚洲激情在线播放| 午夜欧美视频在线观看| 日本不卡不码高清免费观看| 国产精选一区二区三区| 国产1区2区3区精品美女| 99精品久久只有精品| 欧美日韩一区二区三区视频| 日韩欧美一区在线观看| 久久久久国产精品人| 一区二区中文视频| 视频在线观看91| 国产精品一品视频| 日本高清免费不卡视频| 日韩视频一区在线观看| 国产欧美一二三区| 亚洲一区二区三区视频在线| 蜜臀av在线播放一区二区三区| 国产精品亚洲午夜一区二区三区| 91婷婷韩国欧美一区二区| 91精品婷婷国产综合久久性色 | 欧美一级搡bbbb搡bbbb| 国产欧美1区2区3区| 亚洲成av人片| 国产精品88888| 欧美图区在线视频| 国产亚洲va综合人人澡精品| 亚洲影院在线观看| 国产精品一区三区| 91麻豆精品国产91久久久使用方法| 国产欧美视频在线观看| 丝袜国产日韩另类美女| 成人精品在线视频观看| 91麻豆精品国产综合久久久久久| 欧美国产一区二区| 免费xxxx性欧美18vr| 91视频免费看| 国产日产亚洲精品系列| 日韩激情在线观看| 日韩午夜电影av| 亚洲日本va在线观看| 国产成人亚洲精品狼色在线| 88在线观看91蜜桃国自产| 亚洲蜜桃精久久久久久久| 韩国av一区二区| 3d动漫精品啪啪一区二区竹菊| 欧美国产一区二区| 激情小说亚洲一区| 555www色欧美视频| 亚洲一区二区在线播放相泽| www.av精品| 欧美激情综合在线| 国产不卡视频在线观看| 日韩一区和二区| 免费观看久久久4p| 在线播放中文一区| 日本特黄久久久高潮| 欧美亚洲综合另类| 一级做a爱片久久| 色综合天天综合网国产成人综合天 | 午夜视频一区在线观看| eeuss鲁片一区二区三区在线看| 久久蜜桃香蕉精品一区二区三区| 奇米影视在线99精品| 日韩午夜在线播放| 另类中文字幕网| 精品国产一区a| 久久狠狠亚洲综合| 欧美精品一区二区三区高清aⅴ | 中文字幕一区二区三中文字幕| 久久99精品国产91久久来源|