use strict;
use warnings;
use Text::CSV;
use Data::Dumper;
use Devel::Peek;
open my $f, ">", "test.tmp";
print $f "\xD0\x81";
close $f;
open my $io, "<", "test.tmp" or die "$!";
my $csv = Text::CSV->new ({ binary => 1, eol => "\012" });
while (my $row = $csv->getline ($io)) {
print Dumper $row;
Dump $row;
}
prints
$VAR1 = [
"\x{401}"
];
SV = IV(0x245c998) at 0x245c9a8
REFCNT = 1
FLAGS = (PADMY,ROK)
RV = 0x2550980
SV = PVAV(0x23f49b8) at 0x2550980
REFCNT = 2
FLAGS = ()
ARRAY = 0x24bdab0
FILL = 0
MAX = 3
ARYLEN = 0x0
FLAGS = (REAL)
Elt No. 0
SV = PV(0x23f22a0) at 0x2412470
REFCNT = 1
FLAGS = (POK,pPOK,UTF8)
PV = 0x260e200 "\320\201"\0 [UTF8 "\x{401}"]
CUR = 2
LEN = 16
that means it interprets input as UTF-8 data and parses it to perl character string
Question is - why?
In documentation I see:
On parsing (both for getline () and parse ()), if the source is marked being UTF8, then all fields that are marked binary will also be be marked UTF8.
But I did not "mark" anything as UTF-8. And what is "marking" here?
How to control this behaviour - when to parse as binary data and when as character strings?
Note that I don't want to use Text::CSV::Encoded, as it's broken now
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.