⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perl 语言-perl 中文教程(第十一章).htm

📁 perl的中文教程
💻 HTM
📖 第 1 页 / 共 4 页
字号:
          <LI>printf:格式化字符串并输出到文件 </LI></UL></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;这里简单回顾一下,再讲一些前面未提到的函数。<BR><A 
      name=1.1.1>1)open函数</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;open函数将文件变量与某文件联系起来,提供访问文件的接口,例如:open(MYVAR, 
      "/u/file"); 
      如果文件打开成功,则返回非零值,否则返回零。缺省地,open打开文件用以读取其内容,若想打开文件以写入内容,则在文件名前加个大于号:open(MYVAR, 
      "&gt;/u/file"); 向已有的文件末尾添加内容用两个大于号:open(MYVAR, "&gt;&gt;/u/file"); 
      若想打开文件作为数据导向的命令,则在命令前加上管道符(|):open(MAIL, "|mail dave");<BR><A 
      name=1.1.2>2)用open重定向输入</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;可以把打开的文件句柄用作向程序输入数据的命令,方法是在命令后加管道符(|),如:<BR>&nbsp;&nbsp;&nbsp;&nbsp;open(CAT, 
      "cat file*|");<BR>&nbsp;&nbsp;&nbsp;&nbsp;对open的调用运行命令cat file* 
      ,此命令创建一个临时文件,这个文件的内容是所有以file打头的文件的内容连接而成,此文件看作输入文件,可用文件变量CAT访问,如:<BR>&nbsp;&nbsp;&nbsp;&nbsp;$input 
      = <CAT>;<BR>&nbsp;&nbsp;&nbsp;&nbsp;下面的例子使用命令w的输出来列出当前登录的所有用户名。<BR></P>
      <BLOCKQUOTE>
        <P>1 : #!/usr/local/bin/perl<BR>2 :<BR>3 : open (WOUT, "w|");<BR>4 : 
        $time = &lt;WOUT&gt;;<BR>5 : $time =~ s/^ *//;<BR>6 : $time =~ s/ 
        .*//;<BR>7 : <WOUT>; # skip headings line<BR>8 : @users = <WOUT>;<BR>9 : 
        close (WOUT);<BR>10: foreach $user (@users) {<BR>11: &nbsp; $user =~ s/ 
        .*//;<BR>12: }<BR>13: print ("Current time: $time");<BR>14: print 
        ("Users logged on:\n");<BR>15: $prevuser = "";<BR>16: foreach $user 
        (sort @users) {<BR>17: &nbsp; if ($user ne $prevuser) {<BR>18: &nbsp; 
        &nbsp; print ("\t$user");<BR>19: &nbsp; &nbsp; $prevuser = $user;<BR>20: 
        &nbsp; }<BR>21: } </P></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;结果输出如下:<BR></P>
      <BLOCKQUOTE>
        <P>Current time: 4:25pm<BR>Users logged on:<BR>&nbsp; dave<BR>&nbsp; 
        kilroy<BR>&nbsp; root<BR>&nbsp; zarquon </P></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;w命令列出当前时间、系统负载和登录的用户,以及每个用户的作业时间和当前运行的命令,如:<BR></P>
      <BLOCKQUOTE><PRE>  4:25pm  up 1 day,  6:37,  6 users,  load average: 0.79, 0.36, 0.28
User     tty       login@  idle   JCPU   PCPU what
dave     ttyp0     2:26pm           27      3 w
kilroy   ttyp1     9:01am  2:27   1:04     11 -csh
kilroy   ttyp2     9:02am    43   1:46     27 rn
root     ttyp3     4:22pm     2               -csh
zarquon  ttyp4     1:26pm     4     43     16 cc myprog.c
kilroy   ttyp5     9:03am         2:14     48 /usr/games/hack
</PRE></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;上例中从w命令的输出中取出所需的信息:当前时间和登录的用户名。第3行运行w命令,此处对open的调用指定w的输出用作程序的输入,用文件变量WOUT来访问该输入。第4行读取第一行信息,即:<BR>&nbsp;&nbsp;&nbsp;&nbsp;4:25pm 
      up 1 day, 6:37, 6 users, load average: 0.79, 0.36, 
      0.28<BR>&nbsp;&nbsp;&nbsp;&nbsp;接下来的两行从这行中抽取出时间。首先,第5行删除起始的空格,然后第6行删去除时间和结尾换行符之间的所有字符,存入变量$time。<BR>&nbsp;&nbsp;&nbsp;&nbsp;第7行从WOUT读取第二行,这行中无有用信息,故不作处理。第8行把剩下的行赋给数组@users,然后第9行关闭WOUT,终止运行w命令的进程。<BR>&nbsp;&nbsp;&nbsp;&nbsp;@users中的每个元素都是一行用户信息,因为本程序只需要每行的第一个单词,即用户名,故10~12行去掉除换行符外的其它字符,这一循环结束后,@users中只剩下用户名的列表。<BR>&nbsp;&nbsp;&nbsp;&nbsp;第13行输出存贮在$time中的时间,注意这时print不需要加上换行符,因为$time中有。16~21行对@users中的用户名排序并输出。因为同一个用户可以多次登录,所以用$preuser存贮输出的最后一个用户名,下次输出数组元素$user时,如果其与$preser相等,则不输出。<BR><A 
      name=1.1.3>3)文件重定向</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;许多UNIX 
      shell可以把标准输出文件(STDOUT)和标准错误文件(STDERR)都重定向到同一个文件,例如在Bourne 
      Shell(sh)中,命令<BR>&nbsp;&nbsp;&nbsp;&nbsp;$ foo &gt; file1 
      2&gt;&amp;1<BR>&nbsp;&nbsp;&nbsp;&nbsp;运行命令foo并把输出到标准输出文件和标准错误文件的内容存贮到文件file1中。下面是用Perl实现这一功能的例子:<BR></P>
      <BLOCKQUOTE>
        <P>1: #!/usr/local/bin/perl<BR>2: <BR>3: open (STDOUT, "&gt;file1") || 
        die ("open STDOUT failed");<BR>4: open (STDERR, "&gt;&amp;STDOUT") || 
        die ("open STDERR failed");<BR>5: print STDOUT ("line 1\n");<BR>6: print 
        STDERR ("line 2\n");<BR>7: close (STDOUT);<BR>8: close (STDERR); 
      </P></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;运行后,文件file1中的内容为:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      line 2<BR>&nbsp;&nbsp;&nbsp;&nbsp; line 
      1<BR>&nbsp;&nbsp;&nbsp;&nbsp;可以看到,这两行并未按我们想象的顺序存贮,为什么呢?我们来分析一下这段程序。<BR>&nbsp;&nbsp;&nbsp;&nbsp;第3行重定向标准输出文件,方法是打开文件file1将它与文件变量STDOUT关联,这也关闭了标准输出文件。第4行重定向标准错误文件,参数&gt;&amp;STDOUT告诉Perl解释器使用已打开并与STDOUT关联的文件,即文件变量STDERR指向与STDOUT相同的文件。第5、6行分别向STDOUT和STDERR写入数据,因为这两个文件变量指向同一个文件,故两行字符串均写到文件file1中,但顺序却是错误的,怎么回事呢?<BR>&nbsp;&nbsp;&nbsp;&nbsp;问题在于UNIX对输出的处理上。当使用print(或其它函数)写入STDOUT等文件时,UNIX操作系统真正所做的是把数据拷贝到一片特殊的内存即缓冲区中,接下来的输出操作继续写入缓冲区直到写满,当缓冲区满了,就把全部数据实际输出。象这样先写入缓冲区再把整个缓冲区的内容输出比每次都实际输出所花费的时间要少得多,因为一般来说,I/O比内存操作慢得多。<BR>&nbsp;&nbsp;&nbsp;&nbsp;程序结束时,任何非空的缓冲区都被输出,然而,系统为STDOUT和STDERR分别维护一片缓冲区,并且先输出STDERR的内容,因此存贮在STDERR的缓冲区中的内容line 
      2出现在存贮在STDOUT的缓冲区中的内容line 
      1之前。<BR>&nbsp;&nbsp;&nbsp;&nbsp;为了解决这个问题,可以告诉Perl解释器不对文件使用缓冲,方法为:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      1、用select函数选择文件<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      2、把值1赋给系统变量$|<BR>&nbsp;&nbsp;&nbsp;&nbsp;系统变量$|指定文件是否进行缓冲而不管其是否应该使用缓冲。如果$|为非零值则不使用缓冲。$|与系统变量$~和$^协同工作,当未调用select函数时,$|影响当前缺省文件。下例保证了输出的次序:<BR></P>
      <BLOCKQUOTE>
        <P>1 : #!/usr/local/bin/perl<BR>2 : <BR>3 : open (STDOUT, "&gt;file1") 
        || die ("open STDOUT failed");<BR>4 : open (STDERR, "&gt;&amp;STDOUT") 
        || die ("open STDERR failed");<BR>5 : $| = 1;<BR>6 : select 
        (STDERR);<BR>7 : $| = 1;<BR>8 : print STDOUT ("line 1\n");<BR>9 : print 
        STDERR ("line 2\n");<BR>10: close (STDOUT);<BR>11: close (STDERR); 
      </P></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;程序运行后,文件file1中内容为:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      line 1<BR>&nbsp;&nbsp;&nbsp;&nbsp; line 
      2<BR>&nbsp;&nbsp;&nbsp;&nbsp;第5行将$|赋成1,告诉Perl解释器当前缺省文件不进行缓冲,因为未调用select,当前的缺省文件为重定向到文件file1的STDOUT。第6行将当前缺省文件设为STDERR,第7行又设置$|为1,关掉了重定向到file1的标准错误文件的缓冲。由于STDOUT和STDERR的缓冲均被关掉,向其的输出立刻被写到文件中,因此line 
      1出现在第一行。<BR><A 
      name=1.1.4>4)指定读写权限</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;打开一个既可读又可写的文件方法是在文件名前加上"+&gt;",如下:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      open (READWRITE, 
      "+&gt;file1");<BR>&nbsp;&nbsp;&nbsp;&nbsp;此语句打开既可读又可写的文件file1,即可以重写其中的内容。文件读写操作最好与库函数seek和tell一起使用,这样可以跳到文件任何一点。<BR>&nbsp;&nbsp;&nbsp;&nbsp;注:也可用前缀"+&lt;"指定可读写权限。<BR><A 
      name=1.1.5>5)close函数</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;用于关闭打开的文件。当用close关闭管道,即重定向的命令时,程序等待重定向的命令结束,如:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      open (MYPIPE, "cat file*|");<BR>&nbsp;&nbsp;&nbsp;&nbsp; close 
      (MYPIPE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;当关闭此文件变量时,程序暂停运行,直到命令cat 
      file*运行完毕。<BR><A name=1.1.6>6)print, 
      printf和write函数</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;print是这三个函数中最简单的,它向指定的文件输出,如果未指定,则输出到当前缺省文件中,如:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      print ("Hello, there!\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp; print OUTFILE 
      ("Hello, 
      there!\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp;第一句输出到当前缺省文件中,若未调用select,则为STDOUT。第二句输出到由文件变量OUTFILE指定的文件中。<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf函数先格式化字符串再输出到指定文件或当前缺省文件中,如:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      printf OUTFILE (“You owe me %8.2f", 
      $owing);<BR>&nbsp;&nbsp;&nbsp;&nbsp;此语句取出变量$owing的值并替换掉串中的%8.2f,%8.2f是域格式的例子,把$owing的值看作浮点数。<BR>&nbsp;&nbsp;&nbsp;&nbsp;write函数使用输出格式把信息输出到文件中,如:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      select (OUTFILE);<BR>&nbsp;&nbsp;&nbsp;&nbsp; $~ = 
      "MYFORMAT";<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      write;<BR>&nbsp;&nbsp;&nbsp;&nbsp;关于printf和write,详见《第x章 格式化输出》。<BR><A 
      name=1.1.7>7)select函数</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;select函数将通过参数传递的文件变量指定为新的当前缺省文件,如:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      select 
      (MYFILE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;这样,MYFILE就成了当前缺省文件,当对print、write和printf的调用未指定文件时,就输出到MYFILE中。<BR><A 
      name=1.1.8>8)eof函数</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;eof函数查看最后一次读文件操作是否为文件最后一个记录,如果是,则返回非零值,如果文件还有内容,返回零。<BR>&nbsp;&nbsp;&nbsp;&nbsp;一般情况下,对eof的调用不加括号,因为eof和eof()是等效的,但与&lt;&gt;操作符一起使用时,eof和eof()就不同了。现在我们来创建两个文件,分别叫做file1和file2。file1的内容为:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      This is a line from the first file.<BR>&nbsp;&nbsp;&nbsp;&nbsp; Here is 
      the last line of the first 
      file.<BR>&nbsp;&nbsp;&nbsp;&nbsp;file2的内容为:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      This is a line from the second and last file.<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
      Here is the last line of the last 
      file.<BR>&nbsp;&nbsp;&nbsp;&nbsp;下面就来看一下eof和eof()的区别,第一个程序为:<BR></P>
      <BLOCKQUOTE>
        <P>1: #!/usr/local/bin/perl<BR>2: <BR>3: while ($line = &lt;&gt;) 
        {<BR>4: &nbsp; print ($line);<BR>5: &nbsp; if (eof) {<BR>6: &nbsp; 
        &nbsp; print ("-- end of current file --\n");<BR>7: &nbsp; }<BR>8: } 
      </P></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;运行结果如下:<BR></P>
      <BLOCKQUOTE>
        <P>$ program file1 file2<BR>This is a line from the first file.<BR>Here 
        is the last line of the first file.<BR>-- end of current file --<BR>This 
        is a line from the second and last file.<BR>Here is the last line of the 
        last file.<BR>-- end of current file --<BR>$ </P></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;下面把eof改为eof(),第二个程序为:<BR></P>
      <BLOCKQUOTE>
        <P>1: #!/usr/local/bin/perl<BR>2: <BR>3: while ($line = &lt;&gt;) 
        {<BR>4: &nbsp; print ($line);<BR>5: &nbsp; if (eof()) {<BR>6: &nbsp; 
        &nbsp; print ("-- end of output --\n");<BR>7: &nbsp; }<BR>8: } 
      </P></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;运行结果如下:<BR></P>
      <BLOCKQUOTE>
        <P>$ program file1 file2<BR>This is a line from the first file.<BR>Here 
        is the last line of the first file.<BR>This is a line from the second 
        and last file.<BR>Here is the last line of the last file.<BR>-- end of 
        output --$ </P></BLOCKQUOTE>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;这时,只有所有文件都读过了,eof()才返回真,如果只是多个文件中前几个的末尾,返回值为假,因为还有要读取的输入。<BR><A 
      name=1.1.9>9)间接文件变量</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;对于上述各函数open, close, 
      print, printf, write, 
      select和eof,都可以用简单变量来代替文件变量,这时,简单变量中所存贮的字符串就被看作文件变量名,下面就是这样一个例子,此例很简单,就不解释了。需要指出的是,函数open, 
      close, write, select和eof还允许用表达式来替代文件变量,表达式的值必须是字符串,被用作文件变量名。<BR></P>
      <BLOCKQUOTE>
        <P>1: #!/usr/local/bin/perl<BR>2: <BR>3: &amp;open_file("INFILE", "", 
        "file1");<BR>4: &amp;open_file("OUTFILE", "&gt;", "file2");<BR>5: while 
        ($line = &amp;read_from_file("INFILE")) {<BR>6: &nbsp; 
        &amp;print_to_file("OUTFILE", $line);<BR>7: }<BR>8: <BR>9: sub open_file 
        {<BR>10: &nbsp; local ($filevar, $filemode, $filename) = @_;<BR>11: 
        <BR>12: &nbsp; open ($filevar, $filemode . $filename) ||<BR>13: &nbsp; 
        &nbsp; die ("Can't open $filename");<BR>14: }<BR>15: sub read_from_file 
        {<BR>16: &nbsp; local ($filevar) = @_;<BR>17: <BR>18: &nbsp; 
        &lt;$filevar&gt;;<BR>19: }<BR>20: sub print_to_file {<BR>21: &nbsp; 
        local ($filevar, $line) = @_;<BR>22: <BR>23: &nbsp; print $filevar 
        ($line);<BR>24: }  </P></BLOCKQUOTE>
      <P><A name=1.2></A><FONT color=#003333>2、跳过和重读数据</FONT> </P>
      <TABLE class=myFont borderColor=forestgreen cellSpacing=0 cellPadding=2 
      border=1>
        <TBODY>
        <TR>
          <TD width=55>
            <DIV align=center><B>函数名</B></DIV></TD>
          <TD width=516><B>seek</B></TD></TR>
        <TR>
          <TD width=55>
            <DIV align=center><B>调用语法</B></DIV></TD>
          <TD width=516>seek (filevar, distance, relative_to);</TD></TR>
        <TR>
          <TD width=55>
            <DIV align=center><B>解说</B></DIV></TD>
          <TD 
            width=516>在文件中向前/后移动,有三个参数:<BR>1、filevar,文件变量<BR>2、distance,移动的字节数,正数向前移动,负数往回移动<BR>3、reletive_to,值可为0、1或2。为0时,从文件头开始移动,为1时,相对于当前位置(将要读的下一行)移动,为2时,相对于文件末尾移动。<BR>运行成功返回真(非零值),失败则返回零,常与tell函数合用。</TD></TR></TBODY></TABLE><BR>
      <TABLE class=myFont borderColor=forestgreen cellSpacing=0 cellPadding=2 
      border=1>
        <TBODY>
        <TR>
          <TD>
            <DIV align=center><B>函数名</B></DIV></TD>
          <TD><B>tell</B></TD></TR>
        <TR>
          <TD>
            <DIV align=center><B>调用语法</B></DIV></TD>
          <TD>tell (filevar);</TD></TR>
        <TR>
          <TD>
            <DIV align=center><B>解说</B></DIV></TD>
          <TD>返回从文件头到当前位置的距离。<BR>注意:<BR>1、seek和tell不能用于指向管道的文件变量。<BR>2、seek和tell中文件变量参数可使用表达式。</TD></TR></TBODY></TABLE>
      <P><A name=1.3></A><FONT color=#003333>3、系统读写函数 </FONT></P>
      <TABLE class=myFont borderColor=forestgreen cellSpacing=0 cellPadding=2 
      border=1>
        <TBODY>
        <TR>
          <TD width=54>
            <DIV align=center><B>函数名</B></DIV></TD>
          <TD width=517><B>read</B></TD></TR>
        <TR>
          <TD width=54>
            <DIV align=center><B>调用语法</B></DIV></TD>
          <TD width=517>read (filevar, result, length, skipval);</TD></TR>
        <TR>
          <TD width=54>
            <DIV align=center><B>解说</B></DIV></TD>
          <TD 
            width=517>read函数设计得与UNIX的fread函数等效,可以读取任意长度的字符(字节)存入一个简单变量。其参数有四个:<BR>1、filevar:文件变量<BR>2、result:存贮结果的简单变量(或数组元素)<BR>3、length:读取的字节数<BR>4、skipval:可选项,指定读文件之前跳过的字节数。<BR>返回值为实际读取的字节数,如果已到了文件末尾,则返回零,如果出错,则返回空串。</TD></TR></TBODY></TABLE><BR>
      <TABLE class=myFont borderColor=forestgreen cellSpacing=0 cellPadding=2 
      border=1>
        <TBODY>
        <TR>
          <TD>
            <DIV align=center><B>函数名</B></DIV></TD>
          <TD><B>sysread</B></TD></TR>
        <TR>
          <TD>
            <DIV align=center><B>调用语法</B></DIV></TD>
          <TD>sysread (filevar, result, length, skipval);</TD></TR>
        <TR>
          <TD>
            <DIV align=center><B>解说</B></DIV></TD>
          <TD>更快的读取数据,与UNIX函数read等效,参数与read相同。</TD></TR></TBODY></TABLE><BR>
      <TABLE class=myFont borderColor=forestgreen cellSpacing=0 cellPadding=2 
      border=1>
        <TBODY>
        <TR>
          <TD>
            <DIV align=center><B>函数名</B></DIV></TD>
          <TD><B>syswrite</B></TD></TR>
        <TR>
          <TD>
            <DIV align=center><B>调用语法</B></DIV></TD>
          <TD>syswrite (filevar, data, length, skipval);</TD></TR>
        <TR>
          <TD>
            <DIV align=center><B>解说</B></DIV></TD>
          <TD>更快的写入数据,与UNIX函数write等效,参数:<BR>1、filevar:将要写入的文件<BR>2、data:存贮要写入数据的变量<BR>3、length:要写入的字节数<BR>4、skipval写操作之前跳过的字节数。</TD></TR></TBODY></TABLE>
      <P><A name=1.4></A><FONT color=#003333>4、用getc读取字符 </FONT></P>
      <TABLE class=myFont borderColor=forestgreen cellSpacing=0 cellPadding=2 
      border=1>
        <TBODY>
        <TR>
          <TD>
            <DIV align=center><B>函数名</B></DIV></TD>
          <TD><B>getc</B></TD></TR>
        <TR>
          <TD>
            <DIV align=center><B>调用语法</B></DIV></TD>
          <TD>$char = getc (infile);</TD></TR>
        <TR>
          <TD>
            <DIV align=center><B>解说</B></DIV></TD>
          <TD>从文件中读取单个字符。</TD></TR></TBODY></TABLE>
      <P><A name=1.5></A><FONT color=#003333>5、用binmode读取二进制文件</FONT> </P>
      <TABLE class=myFont borderColor=forestgreen cellSpacing=0 cellPadding=2 
      border=1>
        <TBODY>
        <TR>
          <TD width=57>
            <DIV align=center><B>函数名</B></DIV></TD>
          <TD width=514><B>binmode</B></TD></TR>
        <TR>
          <TD width=57>
            <DIV align=center><B>调用语法</B></DIV></TD>
          <TD width=514>binmode (filevar);</TD></TR>
        <TR>
          <TD width=57>
            <DIV align=center><B>解说</B></DIV></TD>
          <TD 
        width=514>当你的系统(如类DOS系统)对文本文件和二进制文件有所区别时使用。必须在打开文件后、读取文件前使用。</TD></TR></TBODY></TABLE>
      <P><A name=2></A><FONT color=#003333>二、目录处理函数</FONT> </P>
      <TABLE class=myFont borderColor=forestgreen cellSpacing=0 cellPadding=2 
      border=1>
        <TBODY>
        <TR>
          <TD>
            <DIV align=center><B>函数名</B></DIV></TD>
          <TD><A name=2.1><B>mkdir</B></A></TD></TR>
        <TR>
          <TD>
            <DIV align=center><B>调用语法</B></DIV></TD>
          <TD>mkdir (dirname, permissions);</TD></TR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -