Here is a simpler variant of the approach suggested by
anonymized user 468275 above. It will help you to diagnose the non-ASCII character content of a given file (byte values between 128 and 255), and give you a simple way to copy/paste the numeric references for (strings of) single-byte characters, so you can specify replacements for them. The following script is a simple stdin-stdout filter -- run it like this: "chr-filter.pl orig.file > viewable.file"
#!/usr/bin/perl
while (<>) {
s/([\x80-\xff])/sprintf "\\x{%02x}",ord($1)/eg;
print;
}
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.
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.