Path: utzoo!attcan!uunet!snorkelwacker!ira.uka.de!fuchs From: fuchs@it.uka.de (Harald Fuchs) Newsgroups: comp.lang.perl Subject: unctrl Message-ID: Date: 16 Oct 90 13:58:51 GMT Sender: news@ira.uka.de (USENET News System) Organization: University of Karlsruhe, FRG Lines: 28 I'm looking for the most elegant (terse?) way to do an 'unctrl' operation on a string, i. e. to replace all occurrences of non-printable characters by a printable representation. Examples: \001 -> ^A \177 -> ^? \232 -> M-^Z The only way I could find was: while (<>) { while (/[\200-\377]/) { $c1 = $&; $c2 = pack ('C', ord ($c1) - 0200); s/$c1/M-$c2/; } while (/[\000-\011\013-\037]/) { $c1 = $&; $c2 = pack ('C', ord ($c1) + 0100); s/$c1/^$c2/; } s/\177/^?/g; print; } How about a one-liner, Randal? -- Harald Fuchs ...