Perl 错误:Name";main::outFile“;只用一次

Perl 错误:Name";main::outFile“;只用一次,perl,Perl,我发现perl脚本有问题: use strict; use warnings; use autodie; my $out = "result2.txt"; open outFile, ">$out" or die $!; my %permitted = do { open my $fh, '<', 'f1.txt'; map { /(.+?)\s+\(/, 1 } <$fh>; }; open my $fh, '<', 'f2.txt'; wh

我发现perl脚本有问题:

use strict; 
use warnings;
use autodie;

my $out = "result2.txt";
open outFile, ">$out" or die $!;
my %permitted = do {
    open my $fh, '<', 'f1.txt';
    map { /(.+?)\s+\(/, 1 } <$fh>;
};

open my $fh, '<', 'f2.txt';
while (<$fh>) {
    my ($phrase) = /(.+?)\s+->/;
    if ($permitted{$phrase}) { print outFile $phrase ;}
}

close outFile;
有什么想法吗


谢谢

打印
有一种非常特殊的语法。没有
时,使用autodie

print outFile $phrase;
意味着

打印
更换
使用autodie创建不能完全复制。它可能最终会成为

print "outFile" $phrase;
它仍然做正确的事情,但对“仅使用一次”警告检查器隐藏了
outFile
的使用

这种警告是虚假的,在这种情况下是无害的。您可以通过避免不必要地使用全局变量来防止它被发出

open my $outFile, ">$out" or die $!;
print $outFile $phrase;
close $outFile;

print
有一种非常特殊的语法。没有
时,使用autodie

print outFile $phrase;
意味着

打印
更换
使用autodie创建不能完全复制。它可能最终会成为

print "outFile" $phrase;
它仍然做正确的事情,但对“仅使用一次”警告检查器隐藏了
outFile
的使用

这种警告是虚假的,在这种情况下是无害的。您可以通过避免不必要地使用全局变量来防止它被发出

open my $outFile, ">$out" or die $!;
print $outFile $phrase;
close $outFile;

谢谢,但问题是“我的($phrase)=/(.+?)\s+->/;”内容只是“->”之前的一段文字,但我希望它打印所有行“hello all->Salet(0.5)”,您似乎忘了提及这些内容。您要匹配的字符串是
$\uu
。如果你想输出整个字符串,这就是你应该打印的内容。谢谢,但问题是“我的($phrase)=/(.+?)\s+->/;“内容只是“->”之前的单词片段,但我想打印所有行“hello all->Salt(0.5)”,你似乎忘了提到这些。您要匹配的字符串是
$\uu
。如果要输出整个字符串,就应该打印这个字符串。