in reply to Printing escaped values of control characters
Using a lookup as suggested by Eliya and Jim but instead of using a regex capture it seems simpler to just split into individual characters and feed into a map doing a lookup in a ternary.
knoppix@Microknoppix:~$ perl -E ' > %esc = ( > qq{\n} => q{\n}, > qq{\r} => q{\r}, > q{ } => q{\s}, > ); > $str = qq{1\r\n 2 \n}; > say qq{Saw $_} for > map { exists $esc{ $_ } ? $esc{ $_ } : $_ } > split m{}, $str;' Saw 1 Saw \r Saw \n Saw \s Saw 2 Saw \s Saw \n knoppix@Microknoppix:~$
I hope this is helpful.
Cheers,
JohnGG
|
|---|