Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1051897]
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2018-06-20 08:38 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.