in reply to Dynamically map the elements of CSV
Split the header line into an array before entering the loop, and then use that to build an AoHs:
use strict; use warnings; my $file = "/tmp/index.csv"; open (FL, "< $file"); my @fieldnames = split ';', <FL>; ## my @data; while ($line = <FL>){ my %temp; @temp{ @fieldnames } = split ';', $line; push @data, \%temp; } ## print the 'Forex' field of the 124th line (array runs from 0). print $data[ 123 ]{ Forex };
|
|---|