zoukankan      html  css  js  c++  java
  • 文件描述符 文件操作 <> open 文件句柄

    #! /usr/bin/perl
    use strict;
    use warnings;

    =head1
    print " ---------------------------------test_--------------------------- ";
    if(!open LOG, ">> Z/logfile"){
        die "can't create logfile: $!";
    }
    print " ---------------------------------test_--------------------------- ";
    =cut

    =head1
    print " ---------------------------------1st_use_FD_read_/etc/passwd_--------------------------- ";
    unless(open PASSWD, "/etc/passwd"){
      die "How did you get logged in? ($!)";
    }
    while(<PASSWD>) {
        chomp;
        print $_;
        print " ";
    }
    print "-----over---- ---------------------------------1st_use_FD_read_/etc/passwd_--------------------------- ";
    close PASSWD;
    =cut1

    =head1
    print " ---------------------------------write_2_file_--------------------------- ";
    unless(open MYLOG, ">> logfile"){
        die "err open logfile: $!";
    }
    my $done = 1;
    my $total = 3;
    print MYLOG "Captain's log, stardate 3.14159 ";
    printf STDERR "%d percent compete. ", $done/$total *100;
    printf (STDERR "%d percent compete. ", $done/$total *100);
    printf STDERR ("%d percent compete. ", $done/$total *100);
    select MYLOG;
    printf ("%d percent compete. ", $done/$total *100);
    select STDOUT;
    print " ---------------------------------write_2_file_--------------------------- ";
    close MYLOG;
    =cut

    =head1
    print " ---------------------------------flush_buffer_--------------------------- ";
    unless(open MYLOG, ">> logfile"){
        die "err open logfile: $!";
    }
    $| = 1;
    print MYLOG "flush buffer immediately after write. ";
    close MYLOG;
    print " ---------------------------------flush_buffer_--------------------------- ";
    =cut

    =head1
    print " ---------------------------------redirect_STDERR_--------------------------- ";
    unless(open STDERR, ">> mySTDERR"){
        die "err open STDERR (>> mySTDERR): $!";
    }
    printf (STDERR "%d percent compete. ", 1/3 *100);
    print " ---------------------------------redirect_STDERR_--------------------------- ";
    =cut

    print " ---------------------------------_--------------------------- ";

    #you should always check the return value of open, since the rest of the
    #program is relying upon its success.

  • 相关阅读:
    浅谈MSSQL2012中的列存储索引(columnstore indexes)
    《高性能SQL调优精要与案例解析》新书样章
    关系库执行计划中三种最常用连接方式的伪码实现
    python基础-字符串
    python基础-文件和目录
    python基础-列表
    python基础-对象
    python基础-入门
    python算法-二叉树广度优先遍历
    Python算法-二叉树深度优先遍历
  • 原文地址:https://www.cnblogs.com/books2read/p/11004061.html
Copyright © 2011-2022 走看看