in reply to replacing special characters in file
So, in the output, you'll see things like "\x{e8}" if the input contained an iso-8859-1 encoded version of "è", and so on.#!/usr/bin/perl while (<>) { s/([\x80-\xff])/sprintf "\\x{%02x}",ord($1)/eg; print; }
If the input data you're working with happens to be utf8-encoded, then it will be better to use "binmode( ':utf8' )" on the file handle before reading the data, and then you just treat the stuff like unicode characters (see perldoc perlunicode).
Ideally, you'll be able to tell from the context around a give (string of) "\x{HH}" symbol(s) what sort of thing you want to replace it with.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: replacing special characters in file
by Anonymous Monk on Jul 18, 2007 at 22:07 UTC |