I\'m trying to escape several special characters in a given string using perl regex. It works fine for all characters except for the dollar sign. I tried the following:
$
has special meaning in regexp, namely "end of string". You would be better off with something like this:
# escape special characters, join them into a single line
my $chars = join '', map { "\\$_" } keys %special_characters;
$string =~ s/([$chars])/$special_characters{$1}/g;
Also, perl doesn't like "$"
much, better use '$'
(single quotes => no interpolation).
UPDATE: Sorry, I was writing this in a hurry => too many edits :(