Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
!/usr/bin/perl -Tw #use T taint, and W warnings use strict; use Data::Dumper; require Text::CSV; #---------------------------------------------------------- sub printRow{ #input the row number print Dumper(@d_array); } #---------------------------------------------------------- #read the csv my $csv_filename="test.csv"; # Getting input into working file my $line; my $line_number; my $csv = Text::CSV->new; my $separator = ','; my $column = ''; my @d_array; my $cnt; unless (open(INFILE, $csv_filename)){ print "Cannot open file \"$csv_filename\"\n"; exit; } foreach $line (<INFILE>){ $line_number++; if ($csv->parse($line)) { my @field = $csv->fields; my $count = 0; for $column (@field) { ++$count; $d_array[$line_number][$count]=$column; } } else { my $err = $csv->error_input; print "parse() failed on argument: ", $err, "\n"; } close INFILE } print Dumper(@d_array); &printRow($cnt);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: dynamic 2d array
by GrandFather (Saint) on Aug 14, 2008 at 02:02 UTC | |
Re: dynamic 2d array
by jethro (Monsignor) on Aug 14, 2008 at 00:28 UTC | |
by Anonymous Monk on Aug 14, 2008 at 03:45 UTC | |
by amarquis (Curate) on Aug 14, 2008 at 13:45 UTC | |
Re: dynamic 2d array
by NetWallah (Canon) on Aug 14, 2008 at 01:10 UTC | |
Re: dynamic 2d array
by dreadpiratepeter (Priest) on Aug 14, 2008 at 00:05 UTC | |
by Anonymous Monk on Aug 14, 2008 at 00:08 UTC | |
by broomduster (Priest) on Aug 14, 2008 at 00:30 UTC | |
Re: dynamic 2d array
by Tux (Canon) on Aug 18, 2008 at 17:15 UTC |