It works on a UTF-16 CSV file.
use v5.14;
use strict;
use warnings;
use utf8;
use autodie qw( open close );
use Text::CSV_PP;
@ARGV == 1 or die "Usage: perl $0 <CSV file>\n";
my $file = shift;
open my $fh, '<:raw:perlio:encoding(UTF-16):crlf', $file;
my $csv = Text::CSV_PP->new({
sep_char => '🎬',
quote_char => '🎥',
escape_char => '🎥',
binary => 1,
});
my @rows;
while (my $row = $csv->getline($fh)) {
push @rows, $row;
}
$csv->eof() or $csv->error_diag();
close $fh;
binmode STDOUT, ':raw:perlio::encoding(UTF-16LE):crlf';
for my $row (@rows) {
$row->[4] =~ s/\n\s*/, /g;
printf "%-24s %s\n", $row->[0], $row->[4];
}
exit 0;
See these nodes for an explanation of the UTF-16 PerlIO nonsense required on Microsoft Windows.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|