YUANya

导航

 

输入文件句柄

#!/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.

posted on 2019-06-16 17:53  YUANya  阅读(108)  评论(0编辑  收藏  举报