这让我发疯,一旦我输入 if 语句,Perl 就会丢失变量的值......而且奇怪的是,它只是那个变量,任何其他变量都不会失去它的值
open (MYFILE, "b");
my $haysack = "";
while (<MYFILE>)
{
$haysack = $haysack . "$_";
}
close (MYFILE);
open (MYFILE2, "ip_range");
my $needles = "";
while (<MYFILE2>)
{
$needles = $needles . "$_";
}
close (MYFILE2);
my $someOtherValue = "blabla";
while ($needles =~ m/(.*?)\n/g)
{
$needle = $1;
if ($haysack =~ m/$needle/ims)
{
print "FOUND : $needle\n";
print "$someOtherValue\n";
}
}
所以代码成功地进入了 if 语句,但是一旦它完成,我得到以下输出:
FOUND:
blabla
谁能帮忙?