Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: better way to escape escapes

by andal (Friar)
on Apr 16, 2014 at 09:23 UTC ( #1082469=note: print w/ replies, xml ) Need Help??


in reply to better way to escape escapes

Do you have to use regexp? In the past, I've solved this issue by splitting string on "escapes", and then walking all parts merging 2 subsequent "escapes" into character and placing them back into text.

Something like this

my @parts = split /([\\@])/, $input; my $txt = shift @parts; while(@parts > 1) { shift @parts; my $t = shift @parts; if($t eq '') { # get the escaped "escape" $txt .= shift @parts; # get the text that follows it $txt .= shift @parts; next; } $t =~ s/^(\w+)//; my $cmd = $1; $txt .= "::$cmd\::$t"; } $txt .= shift @parts if @parts;


Comment on Re: better way to escape escapes
Download Code
Re^2: better way to escape escapes
by RonW (Hermit) on Apr 16, 2014 at 14:50 UTC
    Divide and Conquer looks a lot simpler. Also looks promising.

    Thanks.

    FYI, examples of the data interpretations:

    abc@def@@ghi => abcXef@ghi
    abc@def\@ghi => abcXef@ghi
    abc\def\\ghi => abcXef\ghi
    abc\def@\ghi => abcXef\ghi

    where d represents any directive and X represents the result.
Re^2: better way to escape escapes
by RonW (Hermit) on Apr 16, 2014 at 16:06 UTC
    Thanks. Much better.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1082469]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2014-12-28 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls