I tried running your regex on 2 different lines. The first sample line failed and the second one passed (although its not producing the results I think you want).
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use constant
STATUS_COMPLETED_RE => qr{ ^string-here \s string-here: \s
\((\w+)\) \s #alarm level
([\w|\s]+) \s completed, \s #job completed
Total\s (\d+) \sclient\(s\), \s #total client
+s
( #Details -
(\d+) \s # number
([\w|\s\(\)]+) ,|\. # su
+cceed,fail,etc.
)* # any numbe
+r of
}xms
;
my @sample_str = ('string-here string-here: (alarm_level_5) group5 com
+pleted, Total 55 client(s),',
'string-here string-here: (alarm_level_2) group2 completed, To
+tal 22 client(s), 422 succeed,622 fail,911 no_pass.');
my (@data, %stats);
for my $line ( @sample_str ) {
if (@data = ($line =~ STATUS_COMPLETED_RE )) {
print Data::Dumper->Dump([\@data], [qw/*data/]);
$stats{level} = shift @data;
$stats{group} = shift @data;
$stats{total} = shift @data;
}
else {
print "No match\n";
}
}
print Data::Dumper->Dump([\%stats], [qw/*stats/]);
Output from running the program was:
C:\perlp>perl try.pl
No match
@data = (
'alarm_level_2',
'group2',
'22',
'622 fail,',
'622',
'fail'
);
%stats = (
'group' => 'group2',
'level' => 'alarm_level_2',
'total' => '22'
);
C:\perlp>C:\perlp>
The first sample failed because of line: Total\s (\d+) \sclient\(s\), \s #total client
The \s requires a space even if there isn't a details section that follows. It could be fixed with \s?.In parsing the details section, notice from the output that @data, only picked up the second detail set.
It did this because it only captures the last successful match. First, it captured 422 succeed,, then 622 fail, and failed to match 922 no_pass (because the line doesn't end in a comma). Also, it's capturing the whole detail section and the separate 2 items inside the details. I think what you mean (?) is to capture all the detail groups as a whole (i.e., 422, 622 and 911 and their status). If thats what you mean, then this might be the code:
|