Этот код (взят непосредственно из документации Text :: CSV):
#!/usr/bin/perl
use strict;
use Text::CSV;
use Data::Dumper;
my $rows;
my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute.
or die "Cannot use CSV: ".Text::CSV->error_diag ();
open my $fh, "<", "test.csv" or die "test.csv: $!";
while ( my $row = $csv->getline( $fh ) ) {
push @{$rows}, $row;
}
$csv->eof or $csv->error_diag();
close $fh;
# This gets rid of spaces at start and end of string
# as well as newlines within the fields.
for ( 0 .. scalar @{$rows}-1 ) {
$rows->[$_][2] =~ s/^\s*//;
$rows->[$_][2] =~ s/\n/ /gms;
}
print Dumper($rows);
Создает следующий вывод:
$VAR1 = [
[
'1',
'A',
'Length of x, where x is y'
],
[
'2',
'B',
'Set A to “10”, an invalid state'
],
[
'3',
'C',
'Solve A+B and B+A '
],
[
'4',
'D',
'Set C to B'
]
];
Что (я предполагаю) - это то, что вы хотитедостичь.