• 文件描述符 文件操作 <> 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.

  • 相关阅读:
    【Eclipse】Eclipse常用操作
    编码规范系列(一):Eclipse Code Templates设置
    eclipse code templates 设置(eclipse注释模版配置)
    Eclipse代码注释模板-code template
    善用Eclipse的代码模板功能
    ppt五种经典字体组合
    C++对象模型——指向Member Function的指针 (Pointer-to-Member Functions)(第四章)
    (一二一)核心动画基础
    六:二叉树中第k层节点个数与二叉树叶子节点个数
    gdb 调试利器
  • 原文地址:https://www.cnblogs.com/books2read/p/11004061.html
Copyright © 2020-2023  润新知