in reply to extracting data from CSV files and making hash of hashes

One problem is that you need to change the separator character for Text::CSV to ";". Another problem is that you are not populating your HASHES OF HASHES data structure. I created 2 tiny CSV files for myself, named 1.csv and 2.csv.
use strict; use warnings; use Data::Dumper; use Text::CSV; use File::Basename; my @files = glob '*.csv'; my %hMFD; foreach my $file (@files){ my $file_base = fileparse($file, qr/\.csv/); my $csv = Text::CSV->new({sep_char => ';'}); open (CSV, "<", $file) or die $!; while (<CSV>) { if ($csv->parse($_)) { my @columns = $csv->fields(); $hMFD{$file_base}{$columns[0]} = $columns[1]; } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } } close CSV; } print Dumper(\%hMFD); __END__ $VAR1 = { '1' => { 'Table' => 'M', 'Data' => 'O' }, '2' => { 'Table' => 'X', 'Data' => 'Y' } };

Replies are listed 'Best First'.
Re^2: extracting data from CSV files and making hash of hashes
by reez (Novice) on Jul 21, 2010 at 11:07 UTC

    This works just fine, I`ve added lines to print dumper into a file, still is there easy way to get this hash sorted in a order the files appear in directory?Thanks a lot.