in reply to efficient char escape sequence substitution
I couldn't tell you if it's more efficient, but it's at least an alternative.sub de_slashify { my $string = shift; my $esc = { n => "\n", r => "\r", t => "\t", }; $string =~ s/\\([nrt])/$esc->{ $1 }/ge; return $string }
Update:
(On a tip from Animator)
I should point out that this very simple code snippet won't handle all escape sequences, only the (initial) three you asked about. If you need to parse anything that might contain other more complex escape sequences you should probably use a module.
|
|---|