I have an array @fields containing names for the tab-separated values in $record (it may have been populated from record 0 of the file, for instance).
The order of the array entries corresponds to the order of the values in the record.
I want to populate %hash with field => value entries for each value in the record.
Is there a one-liner to do this? I can’t figure out how to coordinate traversing the @fields and split(“\t”, $record) list concurrently.
Best I can come up with is
my %hash;
my @values = split("\t", $record);
for my $field (@fields) {
my $value = shift @values;
$hash{$field} = $value;
}
But I suspect there’s a simpler way to do it.
Thanks.
There is — it’s the hash slice notation:
or