http://www.perlmonks.org?node_id=1051897


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