Hi.
I'm new to perl, and not expert in any particular programming language.
I've written a script that does the following:
1) Takes a list in FileA as input to a hash (%GrepPatternHash).
2) Takes a list in FileB as input to an array (@TargetList).
2) Uses the elements of that hash as the search pattern to Grep for in the array.
3) Outputs matched strings to FileC.
Problem:
Grep returns matches only if the whole element in the hash matches the whole element in the array precisely.
I need it to return matches of substrings within the array elements, e.g.
abc in FileA matches/returns abc in FileB.
abc in FileA does not match/return zabcd in FileB.
I need both of these conditions to return a match.
Efforts so far:
a) I've tried concatenating wildcard characters to $GrepPatternHash{$_}, such as '.*' and '\b'. They've returned errors or many false matches (respectively).
b) I've tried including same wildcards in FileA ahead of time. They seem to have been treated as literals rather than meta characters.
It seems like there should be an easy way to do this, but I've had no luck finding a solution.
Any help is greatly appreciated.
makwise.
I'm new to perl, and not expert in any particular programming language.
I've written a script that does the following:
1) Takes a list in FileA as input to a hash (%GrepPatternHash).
2) Takes a list in FileB as input to an array (@TargetList).
2) Uses the elements of that hash as the search pattern to Grep for in the array.
3) Outputs matched strings to FileC.
Problem:
Grep returns matches only if the whole element in the hash matches the whole element in the array precisely.
I need it to return matches of substrings within the array elements, e.g.
abc in FileA matches/returns abc in FileB.
abc in FileA does not match/return zabcd in FileB.
I need both of these conditions to return a match.
Code:
@GrepResults = grep ($GrepPatternHash{$_}, @TargetList);
Efforts so far:
a) I've tried concatenating wildcard characters to $GrepPatternHash{$_}, such as '.*' and '\b'. They've returned errors or many false matches (respectively).
b) I've tried including same wildcards in FileA ahead of time. They seem to have been treated as literals rather than meta characters.
It seems like there should be an easy way to do this, but I've had no luck finding a solution.
Any help is greatly appreciated.
makwise.