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.

  • 相关阅读:
    3.2.2.5 BRE运算符优先级
    随机场(Random field)
    D-Separation(D分离)-PRML-8.22-Graphical Model 五 18 by 小军
    CVPR 2013 关于图像/场景分类(classification)的文章paper list
    Introduction to One-class Support Vector Machines
    SVM学习资料
    MIT牛人解说数学体系
    牛顿法与拟牛顿法学习笔记(五)L-BFGS 算法
    牛顿法与拟牛顿法学习笔记(四)BFGS 算法
    牛顿法与拟牛顿法学习笔记(三)DFP 算法
  • 原文地址:https://www.cnblogs.com/books2read/p/11004061.html
Copyright © 2011-2022 走看看