Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Problem with utf8 after nearly 4096 bytes

by McA (Curate)
on Sep 02, 2013 at 07:34 UTC ( #1051897=note: print w/ replies, xml ) Need Help??


in reply to Re: Problem with utf8 after nearly 4096 bytes
in thread Problem with utf8 after nearly 4096 bytes

Hi,

it's just a guess from my side what "Anonymous Monk" wanted to avoid with his recommendation. When you read a file block wise it could happen that the last byte in your buffer is the first byte of a two or more byte representation of a character. An example, the German has the following UTF-8 representation: 0xc3 0x84

xxxxxx 0xc3|0x84 xxxxxx -----------^ End of buffer

This could lead to decoding errors. But when you read AND DECODE linewise you can be pretty sure that all bytes read until NL (or whatever your line ending is) can be decoded properly.

Putting a decoding layer to your filehandle should also work with the handle you get from an upload, so

binmode($fh, ":utf8");

should be valid too.

McA


Comment on Re^2: Problem with utf8 after nearly 4096 bytes
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1051897]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-10-02 11:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (55 votes), past polls