Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^6: Speeds vs functionality

by Jim (Curate)
on Aug 01, 2014 at 18:23 UTC ( [id://1095943]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Speeds vs functionality
in thread Speeds vs functionality

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-24 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found