
Hash
New User
Aug 11, 2009, 4:40 AM
Post #1 of 4
(416 views)
|
|
A Problem Using Regular Expression String Search
|
Can't Post
|
|
Hi, I have a file (say A) containing some words on each line. I need to write a script such that the script opens file A, then reads one line (one word) at a time from file A and searches for the word in another file B. If it finds the word picked up from file A in file B, then the script starts copying an entire line starting from the match position and prints it out. The problem is, the words in file A have characters like "|", "/", "\", "." etc. Example: "CAT|56M.67_8A". When I put that kind of a word into a variable ($A) and then substitute the variable in a reg. exp. (Example: $B =~ /$A/), the special characters in the word ("|", ".", and "_") are INTERPRETED. But, I want to match the special characters AS THEY ARE, without interpreting them. How could I do that? For example: ===================================== <File B> CAT|56M.67_8A - Description: ABCDEFGHI. ===================================== If I search "CAT|56M.67_8A" in the file B (above) containing an additional description attached to the match text, the perl script should pick up the entire line, including the description. But, the script currently interprets "|" to mean "OR" and therefore does not find a match even when the term is present right there in file B. I don't want perl to interpret the special meaning of "|", but rather match it as-it-is. Could anyone please help? Thanks.
|