I have a large tab-delimited data file:
e.g. Town\tCounty Westminster\tGreater London King's Cross\tGreater London Mayfair (north)\tGreater London Mayfair (south)\tGreater London ...
what i am doing is a count of some things, then adding a value to each list item;
Town\tCounty\tVALUE
love perl for how easy this (generally) is;
$tmp=(get the file contents); $tmp=~s/\r//g; $tmp="\n$tmp\n"; ($n,$v)=[got from somewhere, same as list items] ($ctr)=[got from somewhere else] ($rctr)=[count of replacements made] ## attempt 1 if ($tmp=~/^$n\t$v$/) { $tmp=~s/^$n\t$v$/$n\t$v\t$ctr/; $rctr++; } else { ....
THE PROBLEM is that if $n contains brackets () or a single quote ', then it doesn't match. Now, the following fixes the brackets, it matches fine, BUT NOT THE QUOTE. I cannot match or replace the list items with single quotes (apostrophes):
# attempt 2 $n=~s/\(/\\(/g; ## << this works ok! $n=~s/\)/\\)/g; $n=~s/\'/\\'/g; ## << same method, NO WORK!</font> if ($tmp=~/^$n\t$v$/) { $tmp=~s/^$n\t$v$/$n\t$v\t$ctr/; $gctr++; }
How do i fix this? Anyone? Help gratefully appreciated!
In reply to Not matching a single quote (apostrophe!) by puddleglum
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |