Perl 如何解析报告并生成不同条件的摘要?

Perl 如何解析报告并生成不同条件的摘要?,perl,Perl,我想从文件中删除特定的行 我想要的结果是: The Nodes that Running are: ls_sfda-new,risto4, The Nodes that isnt Running are: atum1, The Nodes that Buffering are: vmatum3, The Nodes that Cannot get status are: vcmobile, 我的文本(包含大约60个节点): 我的代码(我知道我需要一个elsif循环,但我需要一些帮助): #/u

我想从文件中删除特定的行

我想要的结果是:

The Nodes that Running are: ls_sfda-new,risto4,
The Nodes that isnt Running are: atum1,
The Nodes that Buffering are: vmatum3,
The Nodes that Cannot get status are: vcmobile,
我的文本(包含大约60个节点):

我的代码(我知道我需要一个
elsif
循环,但我需要一些帮助):

#/usr/bin/perl
严格使用;
打开(文件“/tmp/agentstas.dat”);
我的@lines=;
我的$line;
my$string=“Node”;
my$badstring=“hpom”;
my$buffering=“buffering”;
我的$Running=“Running”;
我的$isnt=“isnt”;
我的$cannote=“cannote”;
foreach$行(@行){
如果($lines=~/^$string/i | |$lines!~/^$badstring/i){
打印“$行”;
}

这比您想象的要容易,使用
$/
-记录分隔符。将其设置为双线馈送,然后您可以匹配记录,而不是单个行:

#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;

local $/ = "\n\n";

open ( my $input, '<', '/tmp/agentstas.dat') or die $!;
while ( <$input> ) {
    my ($name) = m/Node (\w+)/; 
    my %proc_state = m/(\w+)\s+\(\d+\) (.*)/g; 
    print Dumper \%proc_state; 

    if ( m/isnt running/ ) { 
          print "$name not running\n"; 
    }

    if ( m/buffering/ ) { 
         print "$name buffering\n";
    }

    if ( m/Cannot get status information/ ) {
         print "$name no status information\n"
    }

    if ( defined $name and not keys %proc_state ) { 
        print "No process states from $name\n"; 
    }
}
close ( $input ); 
!/usr/bin/env perl
严格使用;
使用警告;
使用数据::转储程序;
本地$/=“\n\n”;

打开(my$input,'请格式化您的帖子。添加
使用警告
。检查
open()
的返回值。使用词法文件句柄和
open()的三参数版本
。哦,给我们展示至少可以编译的代码是一个好主意。可能与“试着问问题”重复。@tripleee这不是那篇文章的重复,因为这个问题的标题有误导性。这个问题的标题应该更接近于“如何解析报告并生成不同条件的摘要?”你好,Sobeique,当我尝试运行脚本时,它说:名称“main::Dumper”只使用了一次:k.pl第11行未打开的filehandle转储程序上的k.pl第11行的print()可能有误,chunk 1.print()在k.pl第11行的未打开的filehandle转储程序上,chunk 2.print()在k.pl第11行的未打开文件句柄转储程序上,chunk 3.thats print:$VAR1={'ovbbccb'=>'正在运行','coda'=>'正在运行','ovconfd'=>'正在运行','opcmona'=>'正在运行','opcle'=>'正在运行','opcacta'=>'正在运行','opcmsgi'=>'正在运行'};$VAR1={'ovbbccb'=>'正在运行'、'opcacta'=>'正在运行'、'ovcd'=>'正在运行'、'opcmsga'=>'正在运行'};我希望它像结果一样运行。请帮助我。您错过了一个;但这就是收集数据的方法。请按照您的意愿格式化它。
#!/usr/bin/perl
use strict;

open (FILE, "/tmp/agentstas.dat");
my @lines = <FILE>;
my $lines;
my $string = "Node";
my $badstring = "hpom";
my $buffering = "buffering";
my $Running = "Running";
my $isnt = "isnt";
my $Cannot = "Cannot";

foreach $lines (@lines) {
    if ($lines =~ /^$string/i || $lines !~ /^$badstring/i) { 
        print "$lines";
    }
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;

local $/ = "\n\n";

open ( my $input, '<', '/tmp/agentstas.dat') or die $!;
while ( <$input> ) {
    my ($name) = m/Node (\w+)/; 
    my %proc_state = m/(\w+)\s+\(\d+\) (.*)/g; 
    print Dumper \%proc_state; 

    if ( m/isnt running/ ) { 
          print "$name not running\n"; 
    }

    if ( m/buffering/ ) { 
         print "$name buffering\n";
    }

    if ( m/Cannot get status information/ ) {
         print "$name no status information\n"
    }

    if ( defined $name and not keys %proc_state ) { 
        print "No process states from $name\n"; 
    }
}
close ( $input );