I need help figuring out how to accomodate situations in which $hash {$i} is loaded with @headers array of different sizes. use strict; use warnings;
my $file = "list.csv";
open (FILE,"$file") || die "Can't open file: $!\n";
my (@lines) = <FILE>;
close(FILE);
my @headers = split(',',$lines[0]);#split up header line
my %hash;
for (my $i=1; $i < scalar(@lines); $i++)
{
my @strings = split(',',$lines[$i];
# NEED help here
$hash{$i} = {
$headers[0] => $strings[0],
$headers[1] => $strings[0],
$headers[2] => $strings[0],
$headers[3] => $strings[0],
$headers[4] => $strings[0],
$headers[5] => $strings[0]
};
}
Is there a way to load up hash at index for in situations when scalar(@headers)=5,6,7 ... etc? Is there a programatic equivalent for something like...
$hash{$i} = {
$headers[0] => $strings[0],
...
$headers[n] => $strings[n]
};
or
$hash{$i} = {@headers => @strings);