From: Mike Stok Date: 2013-05-29T22:43:10+09:00 Subject: Re: AAARRRRGH! s="#$" => SyntaxError: compile error On 2013-05-29, at 8:57 AM, Tadeusz Bochan wrote: > This workaround (avoiding eval) works, but is ever so slow !! > > # convert all \nnn to corresponding character > data=text.gsub(/\\[0-7]{3,4}/) {|r| r.scanf("%c%o").last.chr} > > Can any one suggest something better please ? > > -- > Posted via http://www.ruby-forum.com/. Watch out for the 3 or 4 digit thing there, how can you tell the difference between a value encoded as 3 digits which happens to be followed by a "real" octal digit from the un-encoded data? you either need an explicit terminator e.g. \0123; or \012; or to guarantee the length of the encoded representation. Additionally you need to make sure any literal \ in the input are encoded too so you don't accidentally un-encode sequences which were in your original data. text.gsub(/\\([0-7]{3})/) { $1.to_i(8).chr } might be faster. Hope this helps, Mike -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply.