Perl:错误全局符号需要显式包名称

时间:2015-12-09 13:57:46

标签: perl

您好我正在执行以下脚本但面临以下错误:

Global symbol "$line2" requires explicit package name at Job_Monitoring.pl line 40.
Global symbol "$line2" requires explicit package name at Job_Monitoring.pl line 42.
Global symbol "$line3" requires explicit package name at Job_Monitoring.pl line 43.
Global symbol "$line3" requires explicit package name at Job_Monitoring.pl line 45.
Execution of Job_Monitoring.pl aborted due to compilation errors.

下面是代码。我在尝试比较两个文件的第10个字段时遇到错误,如果匹配则打印整行:

#!/usr/bin/perl
use warnings;
use strict;

open my $fh, "<", "backup_report.txt" or die $!;
open my $outputfile, ">", "long_running_jobs.txt" or die $!;
open my $outputfile1, ">", "active_jobs.txt" or die $!;
open my $outputfile2, ">", "hung_jobs.txt" or die $!;
open my $outputfile3, "<", "hung_jobs_old.txt" or die $!;
open my $outputfile4, ">", "active_jobs_all_fields.txt" or die $!;
open my $outputfile5, ">", "hung_jobs_old.txt" or die $!;
print $outputfile1 "################Active Jobs################\n\n";
print $outputfile "################Long Running Jobs################\n\n";
print $outputfile2 "################Hung Jobs################\n\n";
while (my $line = <$fh>)
{
no warnings 'numeric';
chomp $line;
my @data = split (' ', $line);
if ($data[1] == 0 and $data[2] == 1)
{
    if (! -f $outputfile3)
    {
    print $outputfile3 "$line";
    }
    print $outputfile4 "$line";
    my $acttime=scalar(localtime($data[6]));
    print $outputfile1 "$data[0] $data[3] $data[5] $acttime \n";
    my $currt = time;
    my $efft=($currt-$data[6])/3600;
    if ($efft > 48)
      {
    my $longtime=scalar(localtime($data[6]));
    print $outputfile "$data[0] $data[3] $data[5] $longtime \n";
      }
}
}
my @arr=<$outputfile1>;
my @arr1=<$outputfile3>;
foreach $line2(@arr)
{
my @split=split(' ',$line2);
foreach $line3(@arr1)
{
my @split1=split(' ',$line3);
if($split[9] eq $split1[9])
    {
    print $outputfile2 "$split[0] $split[3] $split[5] $split[6] \n";
    }
print $outputfile5 $outputfile2;
}
}
close $fh;
close $outputfile;
close $outputfile1;
close $outputfile2;
close $outputfile3;
close $outputfile4;
close $outputfile5;

1 个答案:

答案 0 :(得分:1)

strict下,您必须声明使用的每个变量,甚至是循环变量:

foreach my $line2 (@arr)