Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re: reading unicode files by dakkar
in thread reading unicode files by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-24 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found