in reply to Re^2: Text::CSV_XS separator character tab
in thread Text::CSV_XS separator character tab
That file has null bytes in it, which seems to interfere with the Text::CSV_XS parser somehow. If you strip the null characters out of the file, it seems to work ok. (It does for me anyway.)
use warnings; use strict; use Text::CSV_XS; use IO::File; my $file = 'productsYourLenses.txt'; my $fh = new IO::File; $fh->open("< $file") or die "Could not open $file"; my $csv = Text::CSV_XS->new({ 'quote_char' => '', 'escape_char' => '', 'sep_char' => "\t", 'binary' => 1 }); my $columns; while( 1 ){ $columns = $csv->getline($fh); last unless @$columns; print join '|', @$columns, "\n\n"; }
Or, for something this simple you could just use split.
use warnings; use strict; my $file = 'productsYourLenses.txt'; open my $fh, '<', $file or die "Could not open $file $!.\n"; my @rows; while(<$fh>){ chomp; s/\x00//g; my @columns = split /\t+/; push @rows, \@columns; } for (@rows){ print join '|', @$_, "\n\n"; }
Both of these will yield an AoA.
|
|---|