#!/usr/bin/env perl use strict; use warnings; my $c_str = q{BEL \a BS \b ESC \e FF \f NL \n CR \r TAB \t}; $c_str .= q{ VT \v BSLASH \\\\ APOS \' QUOT \" HASH \43}; $c_str .= q{ DOLLAR \x24 AT \u0040 TILDE \U0000007e}; $c_str .= q{ TGs \?= \?/ \?' \?( \?) \?! \?< \?> \?-}; print "\$c_str[$c_str]\n"; my $p_str = c2p($c_str); print "\$p_str[$p_str]\n"; { my %trigraph; BEGIN { no warnings 'qw'; %trigraph = qw{= # / \ ' ^ ( [ ) ] ! | < { > } - ~}; } sub c2p { my ($str) = @_; $str =~ s/\\U([0-9A-Fa-f]{8})/\\x{$1}/g; $str =~ s/\\u([0-9A-Fa-f]{4})/\\x{$1}/g; $str =~ s/\\x([0-9A-Fa-f]+)/\\x{$1}/g; $str =~ s/\\([0-7]{1,3})/0$1/g; $str =~ s/\\\?([=\/'\(\)!<>-])/$trigraph{$1}/g; $str =~ s/\\e/\\c[/g; $str =~ s/\\v/\\x{0b}/g; return $str; } } #### $c_str[BEL \a BS \b ESC \e FF \f NL \n CR \r TAB \t VT \v BSLASH \\ APOS \' QUOT \" HASH \43 DOLLAR \x24 AT \u0040 TILDE \U0000007e TGs \?= \?/ \?' \?( \?) \?! \?< \?> \?-] $p_str[BEL \a BS \b ESC \c[ FF \f NL \n CR \r TAB \t VT \x{0b} BSLASH \\ APOS \' QUOT \" HASH 043 DOLLAR \x{24} AT \x{0040} TILDE \x{0000007e} TGs # \ ^ [ ] | { } ~]