in reply to Simply Too Slow Find and Replace
@newrecords = (@newrecords,"$name");Could be replaced with:
push(@newrecords, $name);Apart from that, you seem to have the right idea. Just make sure your substitution table doesn't contain any "fancy" characters such as brackets or question marks and so forth. If it might, probably best to handle them better:
$name =~ s/\s\Q$key\E/$value/ig;The \Q and \E prevent any of those characters from being treated as special. If you had a $key of 'OPEN?' then it would match both 'OPE' and 'OPEN' which is clearly not what you want. Also, if you are matching words, this is probably a better regex:
$name =~ s/\b\Q$key\E\b/$value/ig;The \b means to match on a word boundary. This way you can replace things like the "HAM" in "RALPH USED A HAM AS A HAMMER" without substituting on "HAMMER".
|
|---|