Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: C strings, unescaping of
by daxim (Curate) on Sep 30, 2013 at 14:05 UTC | |
by Anonymous Monk on Sep 30, 2013 at 15:46 UTC | |
|
Re: C strings, unescaping of
by Marshall (Canon) on Sep 30, 2013 at 14:53 UTC | |
by andal (Hermit) on Oct 01, 2013 at 07:38 UTC | |
|
Re: C strings, unescaping of
by AnomalousMonk (Archbishop) on Oct 01, 2013 at 18:30 UTC | |
by Anonymous Monk on Oct 02, 2013 at 12:23 UTC | |
by Anonymous Monk on Oct 02, 2013 at 15:21 UTC | |
by AnomalousMonk (Archbishop) on Oct 02, 2013 at 20:44 UTC |