Peter Daum wrote: > I am looking for an way to interpolate backslash-sequences > within a string with the usual perl semantics, e.g. > $s='1\t\2\t3\na\ b c' should become: > '1<tab>2<tab>3 > a b c' > > Things I tried were for example > $s= eval('' . "$val"); # (hoping to trigger the normal interpolation) or > $s=~ s/\\(.)/"\\$1"/eg; > but somehow i couldn't get it right ... > > Can anybody think of an elegant solution?
$ perl -le' my %translate = ( t => "\t", n => "\n", r => "\r", f => "\f", b => "\b", a => "\a", e => "\e", ); my $s = q[1\t\2\t3\na\ b c]; print $s; $s =~ s/\\(.)/ exists $translate{ $1 } ? $translate{ $1 } : $1 /seg; print $s; ' 1\t\2\t3\na\ b c 1 2 3 a b c John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>