http://www.perlmonks.org?node_id=1056362

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm parsing (C-style) strings in strace logs, but the problem itself is rather generic. To unescape the strings I've tried:

sub trx { (my $x = $_[0]) =~ tr/rnbaftv/\r\n\b\a\f\t\013/; $x; } $s =~ s{\\([0-7]{1,3})|\\(.)}{defined $1 ? chr oct $1 : trx $2}eg;

Or like this:
  $s =~ s{\\([0-7]{1,3})|\\(.)}{defined $1 ? chr oct $1 : (grep ~y/rnbaftv/\r\n\b\a\f\t\013/, "$2")[0]}eg;

Now the question is, since this appears such a simple common task, isn't there a better more concise way of doing it? Thank you!