This code (taken directly from the Text :: CSV document):
#!/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*
It produces the following output:
$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' ] ];
Which (I guess) is what you want to achieve.
source share