in reply to Re^2: Loader script - Design question
in thread Loader script - Design question

the 'chain' of hashref gets bigger.

That's what selectall_hashref does

The $key_field parameter defines which column, or columns, are used as keys in the returned hash. It can either be the name of a single field, or a reference to an array containing multiple field names. Using multiple names yields a tree of nested hashes.

What structure do you want ?

poj

Replies are listed 'Best First'.
Re^4: Loader script - Design question
by artanisace (Initiate) on Feb 23, 2016 at 13:14 UTC

    I want something like I have when I use text::CSV to read the file and turn it into hashref:

    # Read file from path my @rows; my $csv = Text::CSV->new ( { binary => 1, sep_char => "\t" } ) or die "Error creating TSV object: ".Text::CSV->err +or_diag (); open my $fh, "<:encoding(utf8)", "$filename" or die "Error reading CSV file: $!"; $csv->column_names ($csv->getline ($fh)); # Get header names while ( my $record = $csv->getline_hr( $fh ) ) { # Process record push @rows, $record; } $csv->eof or $csv->error_diag(); close $fh; print Dumper \@rows;

    This is the output after reading the file:

    $VAR1 = [ { 'ID' => '4564', 'Date' => '4-05-1986, 'Name' => 'Mengano' } ];

        Thank you very much, that's what I was searching for! Appreciate it :)