【发布时间】:2017-05-05 05:31:46
【问题描述】:
我有这些问题。但我不知道如何证明它或者我是否正确。我的回答对吗?
查找文件的所有完整行,其中仅包含一行任意数量的字母 x
- x*
- ^x+$
- ^x*$
- ^xxxxx$
查找文件的所有完整行,其中包含仅包含字母 x 但忽略行上任何前导或尾随空格的行。
- ^\s* x+\s*$
- ^\s(x*)\s$
- \s* x+\s*
- ^\s+x+\s+$
我试过用这个
use strict;
use warnings;
my $filename = 'data.txt';
open( my $fh, '<:encoding(UTF-8)', $filename ) or die "Could not open file '$filename' $!";
while ( my $row = <$fh> ) {
chomp $row;
print "$row\n";
}
我尝试了这段代码,但在 (^ 处出现错误
use strict;
use warnings;
my $filename = 'data.txt';
open( my $fh, '<:encoding(UTF-8)', $filename ) or die "Could not open file '$filename' $!";
while ( my $row = <$fh> ) {
if ( ^x*$ ) {
print "This is";
}
}
【问题讨论】:
-
写一些测试怎么样?
-
我试过用这个use strict;使用警告;我的 $filename = 'data.txt'; open(my $fh, '<:encoding or die not open file>){ chomp $row;打印“$行\n”; }
-
我试过这段代码,但在 (^ use strict; use warnings; my $filename = 'data.txt'; open(my $fh, '<:encoding or die not open file while>) { if (^x*$){ print "This is"; } }跨度>
-
问题是什么?
标签: perl