in reply to Re^2: Regexes and backslashes
in thread Regexes and backslashes

OK, how about this one. It's a little bit klunky in its use of a conversion hash, but the hash can easily be expanded as needed.

>perl -wMstrict -le "$_ = 'Goodbye\; Good luck\, and thanks for all the fish!\n\n'; my %conv = ( ',' => ',', ';' => ';', n => qq{\n} ); print qq{[[$_]]}; s{ \\([,;n]) }{$conv{$1}}xmsg; print qq{[[$_]]};; " [[Goodbye\; Good luck\, and thanks for all the fish!\n\n]] [[Goodbye; Good luck, and thanks for all the fish! ]]

Replies are listed 'Best First'.
Re^4: Regexes and backslashes
by oko1 (Deacon) on Feb 16, 2011 at 08:24 UTC

    Heh. Yeah, we could even in-line it:

    s|\\([,;n])|${{',',',',';',';',n=>"\n"}}{$1}|g;

    Nicely confusing. :)

    I guess there really is no way to make this work with a simple char class replacement, though. Oh well.

    -- 
    Education is not the filling of a pail, but the lighting of a fire.
     -- W. B. Yeats

      Cute :)

      Slightly more condensed:

      s/\\([,;n])/${{n=>"\n"}}{$1}||$1/eg;