williams has asked for the wisdom of the Perl Monks concerning the following question:
warn 'tab' unless unescape("\\t") eq "\t"; #works warn 'nl' unless unescape("\\n") eq "\n"; #fails warn 'bel' unless unescape("\\07") eq "\07"; #fails sub unescape { my($s)=@_; $s =~ s/(\\[^\d])/$1/ge; #"\t", "\n", etc. $s =~ s/(\\0\d+)/$1/ge; #"\07", etc. return $s; }
I'm trying to let users type these sequences in input files and interpret them as Perl would within my code. The Perl and PM FAQs have similar questions, but none that solved this for me.
Thanks,
Jim
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unable To Replace Escape Sequences With 1-Char Equivalents
by ikegami (Patriarch) on Oct 20, 2004 at 01:50 UTC | |
|
Re: Unable To Replace Escape Sequences With 1-Char Equivalents
by etcshadow (Priest) on Oct 20, 2004 at 02:32 UTC | |
|
Re: Unable To Replace Escape Sequences With 1-Char Equivalents
by simonm (Vicar) on Oct 20, 2004 at 05:07 UTC |