in reply to Interpretting character combinations as special characters.

my %mapping = ( '\t' => "\t", '\n' => "\n", '\)' => ')'. '\( => '(', ); my $re = join '|', map quotemeta, keys %mapping; $str =~ s/($re)/$mapping{$1}/g;

This has the advantage of not relying on perl's escaping rules (and thus gives you fine control over what's happening), but has the disadvantage that you have to list all replacements.

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: Interpretting character combinations as special characters.
by JavaFan (Canon) on Dec 10, 2009 at 13:32 UTC
    Listing only those mappings that are different from taking off the leading backslash:
    my %mapping = (n => "\n", t => "\t"); $str =~ s{\\(.)}{$mapping{$1}//$1}seg;
    This still gives fine control, but you don't have to list everything.