DespacitoPerl has asked for the wisdom of the Perl Monks concerning the following question:
Hi i am writing a perl. script to extract out the number of errors with each code as a summary. The input is like this
A_01: xxxxxxx xxxxxxxxxx xxx......... 1 violation A_02: xxxxxxx xxxxxxxxxx xxx......... 4 violations B_02: xxxxxxxx xxxxxxxxxx xxx......... 3 violations
So, from the input, basically i have to grep from A_01 until 1 violation, and from here to there is about 3 lines, and the output is like this:
A number of violations = 5; B number of violations = 3;
But, my code is only able to read the violations all though, and sum it out. My code is like tis:
open(DATA, "<abc.txt, $!"; $num = 0; while (<DATA>){ while (<DATA>){ if ( (($_ =~ /violation/) || ($_ =~ /violations/))) { if ($_ =~ /(\d+)/) { $num = $num + $1; } } } if ($num == 0) { print "DM0$x ....... CLEANED\n" } else { print "DM0$x ....... Total = $num violations\n" } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: grep the data out of a text file.
by choroba (Cardinal) on Jul 05, 2017 at 08:40 UTC | |
|
Re: grep the data out of a text file.
by tybalt89 (Monsignor) on Jul 05, 2017 at 08:46 UTC | |
|
Re: grep the data out of a text file.
by Discipulus (Canon) on Jul 05, 2017 at 08:13 UTC | |
|
Re: grep the data out of a text file. (Update 2)
by thanos1983 (Parson) on Jul 05, 2017 at 08:38 UTC |