I have two arrays which contain the following elements:
my @type = ("man", "boy");
my @array = (
"=stat_man",
"=stat_boy"
"=ref_g_man",
"=g_man",
"=g_boy",
"=happy_man" ,
"an element",
"another element",
"=ref_g_boy"
);
As an option, I want to delete only the lines in @array which contain the string 'stat', in the other case, I want it to delete the elements which do not contain the string 'stat', but contain an element of @type. So I wrote:
foreach my $type (@type) {
if(condition) {
@array = grep {! /stat_$type/}@array; #works. Deletes elements with 'stat'
}
else {
@array = grep {! /(?!stat)_$type/}@array; #sort of...works
}
}
Ok, now here's where I get stuck. In the else, all elements that contain $type and do not contain 'stat' are deleted. Which is ok. But what I want is for the second grep to delete only the elements which contain $type, do not contain 'stat' and not delete the elements which have the prefix made up of more that 1 word.
For example, I want
"=g_man" , "=g_boy" and "=happy_man" deleted, but not "=ref_g_man" and "=ref_g_boy".
If I add anything in front of the (?!stat) in the second grep, it doesn't work.
Basically, I'm at loss as to how to add the third condition to the grep.