in reply to Problems with grep
I wonder if you would be better off parsing the "CVE_data_Demo" file into a hash rather than slurping the file into an array and repeatedly greping over it. Then you would be able to do a simple hash lookup for each line of your "found_vulns_test" file. It would be useful to see a sample of the data, sanitised if necessary, to form a better judgement.
It appears that you are matching against an alternation of, for example, 'PARTIAL' or '[P]' but you should note that square brackets are regular expression metacharacters that enclose a character class; in this case a class with a single member, 'P'. They should be escaped to match literals.
... } elsif( /PARTIAL|\[P\]/i ) { ...
Again, I wonder if a hash might be better.
... my %biasedConfLookup = ( COMPLETE => 100, q{[C]} => 100, PARTIAL => 50, q{[P]} => 50, NONE => 0, q{[I]} => 0, ); ... $biasedConf = exists $biasedConfLookup{ uc $_ } ? $biasedConfLookup{ uc $_ } : 0; ...
Another point; you should always check for the success or otherwise of your open statements and it is recommended that you use the three-argument form with lexical filehandles
open my $foundVulnsFH, q{<}, q{found_vulns_test} or die qq{open: < found_vulns_test: $!\n};
and you should avoid using the DATA filehandle for a file you open, as filehandle of that name is opened automatically for you by the perl interpreter if your script contains data inline after __DATA__ or __END__ tags.
I hope these points are helpful.
Cheers,
JohnGG
|
|---|