Path: utzoo!attcan!uunet!aplcen!samsung!cs.utexas.edu!sun-barr!ccut!wnoc-tyo-news!sragwa!sranha!sran230!sran84!utashiro From: utashiro@sran84.sra.co.jp (Kazumasa Utashiro) Newsgroups: comp.lang.perl Subject: Re: unctrl Message-ID: <225@sran84.sra.co.jp> Date: 17 Oct 90 04:45:20 GMT References: Reply-To: utashiro@sra.co.jp (Kazumasa Utashiro) Organization: Software Research Associates, Inc., Japan Lines: 21 In article fuchs@it.uka.de (Harald Fuchs) writes: >> 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 I'm using this script in my perlized a2ps. s/[\200-\377]/sprintf("M-%c",ord($&)-0200)/ge; s/[\000-\007\013\015-\032\034-\037]/sprintf("^%c",ord($&)+0100)/ge; s/\177/^?/g; >> How about a one-liner, Randal? I'd like to see too. --- K. Utashiro utashiro@sra.co.jp