in reply to Interpretting character combinations as special characters.

my $string = 'This is\na special\tstring'; my %replace = map { $_ => eval "\\$_" } (qw( n r t )); $string =~ s/\\(.)/exists $replace{$1} ? $replace{$1} : $1/ge; print $string;

Replies are listed 'Best First'.
Re^2: Interpretting character combinations as special characters.
by afoken (Chancellor) on Dec 10, 2009 at 20:08 UTC

    Three string evals and a map just for lazyness? Why don't you just write my %replace=( n => "\n", t => "\t", r => "\r" );?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Exactly for that reason - I'm lazy, as I want to be able to add 0 without much hassle, and possibly other special characters.