Your immediate problem has been resolved. However there are a few other things you ought to consider:
unless (open(INFILE, $csv_filename)){
print "Cannot open file \"$csv_filename\"\n";
exit;
}
is better written:
open my $inFile, '<', $csv_filename or die qq{Cannot open file "$csv_f
+ilename"\n};
which declares a lexical file handle, uses the safer three parameter version of open and uses the more idiomatic die for error handling.
foreach $line (<INFILE>) {
slurps the file and introduces a variable that, in a subtle fashion, isn't the one you think it is (see Foreach Loops and note that the variable is aliased). You would be better to use a while loop:
while (defined (my $line = <$inFile>)) {
The close INFILE should be outside the loop. It didn't matter for the foreach loop because you were slurping the file, but it will cause trouble for the while loop version.
my @field = $csv->fields;
my $count = 0;
for my $column (@field) {
++$count;
$d_array[$line_number][$count] = $column;
}
is better written:
$d_array[$line_number] = [$csv->fields ()];
Update: oh, and if you use $. instead of $line_number you get the actual file line number. Note though that $d_array[0] at least will be undef using either your current line counting technique or the $. technique.
Perl reduces RSI - it saves typing
|