I want to match all the lines of a file against keys in a hash so that there is a match if the line begins with a key. In order to do that I have created a regex that is a join off all the keys separated by "|"
my $regex = join('|', keys %hash);
then I use the following pattern matching:
if ($line =~ /^($regex)/) {
do something;
}
My problem is that different keys can begin with the same word(s). For instance:
key1 = "aaa bbb ddd"
key2 = "aaa ccc"
key3 = "aaa bbb eee"
key4 = "aaa bbb eee fff"
How to dissociate between these keys ??
Thanks.
my $regex = join('|', keys %hash);
then I use the following pattern matching:
if ($line =~ /^($regex)/) {
do something;
}
My problem is that different keys can begin with the same word(s). For instance:
key1 = "aaa bbb ddd"
key2 = "aaa ccc"
key3 = "aaa bbb eee"
key4 = "aaa bbb eee fff"
How to dissociate between these keys ??
Thanks.