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.

  • 相关阅读:
    2020916 spring总结
    20200915--事务
    20200915-mybatis基础
    20200911--使用注解开发
    20200910--Spring配置
    20200909--spring基础-IOC
    20200909-待补充
    20200909记我所看到的问题
    20200909-spring基础一
    面向对象
  • 原文地址:https://www.cnblogs.com/books2read/p/11004061.html
Copyright © 2011-2022 走看看