zoukankan      html  css  js  c++  java
  • 小骆驼 第五章 输入与输出

    输入文件句柄

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    # cat 1.txt
    # ssssssssssss
    # ssssssssss
    # dddddddddddd
    
    open TXT, '<', '1.txt';binmode TXT;
    
    my $new = '5.txt';open NEW_TXT,'>:encoding(UTF-8)',$new;
    
    foreach(<TXT>)
    {
        chomp;$| = 1;
        
        print NEW_TXT "$_\n";
    }
    
    print "$new\n";
    
    #5.txt
    # cat 5.txt
    # ssssssssssss
    # ssssssssss
    # dddddddddddd
    #
    
    open TXT2 ,'2.txt';my $line = <TXT2>;print "$line";close TXT2;
    
    #my $line1 = <TXT2>;print "$line1\n";
    
    #2222222222
    #
    #readline() on closed filehandle TXT2 at test.pl line 21.
    #Use of uninitialized value $line1 in concatenation (.) or string at test.pl line 21.
    #
    
    #my $wrong = 2;if($wrong != 3){die "wrong!:$!";}
    
    #wrong!:Inappropriate ioctl for device at test.pl line 41.
    
    use 5.010;my @arr = qw(a b c);say @arr;
    
    #abc
    
    my $txt2;open $txt2 ,'2.txt';my $line1 = <$txt2>;say "$line1";close $txt2;
    
    my $txt6;open $txt6,'>6.txt';say $txt6 "$line1";
    
    say $txt6,"$line1";
    
    say $txt6;
    
    #2222222222
    #
    #GLOB(0x1510b68)2222222222
    #
    #GLOB(0x1510b68)
    # cat 6.txt
    # 2222222222
    #
    
    $_ =2;say STDOUT;
    say $txt6;
    
    #2
    #GLOB(0x1510b68)
    

    问题一:这里将文件句柄用大括号围上之后为何还会报错?

    say { $txt6 };
    
    #syntax error at test.pl line 72, near "};"
    #Execution of test.pl aborted due to compilation errors.
    
    
  • 相关阅读:
    bzoj4476: [Jsoi2015]送礼物
    牛客练习赛42 E.热爆了
    bzoj3561: DZY Loves Math VI
    bzoj3560: DZY Loves Math V
    bzoj3512: DZY Loves Math IV
    bzoj3481: DZY Loves Math III
    使用WebUploader本地生成缩略图
    centos 7 安装JDK1.8
    APK反编译
    centos 7 配置pytorch运行环境
  • 原文地址:https://www.cnblogs.com/yuanjingnan/p/11061476.html
Copyright © 2011-2022 走看看