If I have the following array
my @header_line = ('id', 'name', 'age');
How do I create a hash from it equivalent to the line below?
my %fields = { id => 0, name => 1, age => 2};
The reason I want to do this is so that I can use meaningful names rather than magic numbers for indexes. For example:
$row->[$fields{age}]; # rather than $row->[2]
$rowto%row(a hash)?my %row_hash = map { $_ => shift @{$row} } @header_line;. Just another alternative, but might be cleaner using$row_hash{age}than having to use the$row->[$fields{age}]notation...