I have a number of error strings. I am matching them to patterns I already have. If they're the exact same I want them to fall under the exact same error failure. If they match the pattern but have some difference from previous strings in the hash, I want to give it the same error name but with a different number appended to it.
Here's an example input file:
there are 5 syntax issues with semicolon
there are 11 syntax issues with semicolon
the file contains 5 formatting issues
there are 1 syntax issues with semicolon
check script for formatting issues
2 syntax issues have been found
the file contains 1 formatting issues
6 syntax issues have been found
use warnings;
use strict;
my %errors;
my $file = "listoferrormessages.txt"
open my $fh,'<',$file or die "Could not open $file: $!";
while(my $line = <$fh>){
if( $line =~ /syntax/){
if ($line =~ /there are \d syntax issues with semicolon/){
#if line matching format exists in hash values, continue
#if not, create a hash key called syntax_# where # increments one from the last key with the error name.
$errors{errorname} = $line;
}
elsif ($line =~ /\d syntax issues have been found/){
#same as above
$errors(errorname} = $line;
}
elsif ($line =~ /format/){
#same as above
}
}
close $fh;
I would like my hash to look like:
$VAR1 = {
'syntax_1' =>
'there are 5 syntax issues with semicolon',
'syntax_2' =>
'2 syntax issues have been found',
'format_1' =>
'the file contains 5 formatting issues',
'format_2' =>
'check script for formatting issues'
};
Any guidance on this would be super helpful. There's a lot more I'd like to add on but I'm very confused with how I can start doing this. Is this even possible to do?