There is no such thing as "Unicode files".
Unicode is:
- a list of characters, each of which has a number of properties, such as a name and a number, categories to which it belongs, and so on
- a series of algorithms (for bidirectionality, collation, normalization, etc etc)
- some Transfer Formats for serializing character streams
- and some more thing I forgot...
The things of interest here are the transfer formats: the most known are utf-8 and utf-16:
- utf-8
- maps the characters defined in ASCII into their usual representation as bytes with values under 128, allowing non-Unicode-aware programs to not make a mess of it (for example, utf-8-encoded strings can still be 0-terminated, the path separator doesn't change, and so on)
- utf-16
- is more compact for oriental scripts (a kanji in utf-8 can become 4 bytes long, but it's usually 2 bytes long in utf-16), but you can't use 0 to terminate you strings, because for example the character 'A' gets encoded as the two bytes 0 and 65. Moreover, utf-16 is sensitive to endianness
In the following, I'll assume you have utf-8-encoded files.
For Perl 5.005, you just have to handle them as binary files, i.e. you don't have support for Unicode strings.
Perl 5.8 does have support, you just have to tell it which encoding your files are in:
open UTF8FILE,'<:utf8','filename';
while (<UTF8FILE>) {
/\p{Devangari}/ and print "A Devangari character!\n";
}
close UTF8FILE;
This script would open the file assuming it is in
utf-8, and print a message if it finds any character in the Devangari script.
Thing to look at (in the 5.8 docs):
- perldoc -f open
- perldoc perluniintro
- perldoc perlunicode
And also The UTF-8 and Unicode FAQ
--
dakkar - Mobilis in mobile
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.