in reply to grep the data out of a text file.
I must admit that I do not well understand the question; is the following?
> But, my code is only able to read the violations all though, and sum it out.
So specify a bit what you want to implement in your program.
Anyway I have some general hints: always, that means ALWAYS, use strict; use warnings; this force you to write more robust program. strict force you to declare variables with my and this force you to limit the scope of such variables to the minimum required. This is good.
Second: use a more modern and safer way to open your filhadles: open(DATA, "<abc.txt, $!"; is a non sense..
Always use lexical filehandles (not bareword ones) like:
my $file_path = '/some/path/file.txt'; open my $fh, '<', $file_path or die "Impossible read from [$file_path] +! $!"; # read the file and close it as soon as you do not need it anymore close $fh or die "error closing filehandle! $!";
More; your bareword filehandle DATA is very risky: infact DATA is a special filehandle referring to the same program you are running and left open for read pointing just after the special token __DATA__ so do not use it anyway (use lexical filehandle and stop).
The DATA special filehandle is used this way:
use strict; use warnings; while (<DATA>){ chomp; print "$_ "; } print "\n"; __DATA__ welcome to Perl
L*
|
|---|