Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: Problem with utf8 after nearly 4096 bytes

by McA (Priest)
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


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.


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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2016-05-04 06:41 GMT
Find Nodes?
    Voting Booth?