in reply to Regex to dereference

When you ask a question, the monks are happy to see your effort in the shape of the code you tried before asking for help. But when you're confused about how to write down the algorithm or the program or about Perl itself, it could help a prose description of what you're trying to do. Sometimes you'll be surprised about how people may offer simpler solutions you haven't thought about it.

Well, after this unsolicited introduction, I am not sure what you're trying to do. Maybe replacing literal escape sequences like '\n' with their meaning "\n", which could be done with code like

my %map = ( '\n' => "\n", '\t' => "\t" ); $_ = "whatever"; s/(\\[ntf\\])/$map{$1}||'?'/g
Or maybe you're trying to do the opposite: turn newlines ("\n"), tabs ("\t") into escapes ('\n', '\t'). Where something like this might work
my %imap = ( "\n" => '\n', "\t" => '\t' ); my $specials = join '|', keys %imap; $_ = "a\nb\tcksl"; s/($specials)/$imap{$1}/gms;

But you may find useful a ready-to-use module like Text::Quote as well.

Replies are listed 'Best First'.
Re^2: Regex to dereference
by Hena (Friar) on Jan 19, 2007 at 06:43 UTC
    Ah sorry. I tried and obviously didn't do a very good job at it :).

    Idea was to turn '\' into '\\'. Unless its in conjunction with 'n', 't', 'f', 'r', or '\'.