in reply to Re: Populating a hash-ref from multiple arrays with slice?
in thread Populating a hash-ref from multiple arrays with slice?

But if the OP wants it as slice, this is the code:

@array1 = qw(some_unique_key1 some_unique_key2 some_unique_key3); @array2 = qw(meta_data_1 metadata_2 metadat_3); @array3 = qw(submitted_date1 submitted_date2 submitted_date3); my $hashref; # @hash{@keys} = @values; @$hashref{@array1} = map { {'Metadata' =>$array2[$_], 'Submitted Date' +=>$array3[$_]} } 0..$#array1; use Data::Dumper; die Dumper $hashref;

It would then give this as output:

$VAR1 = { 'some_unique_key3' => { 'Submitted Date' => 'submitted_date3', 'Metadata' => 'metadat_3' }, 'some_unique_key2' => { 'Submitted Date' => 'submitted_date2', 'Metadata' => 'metadata_2' }, 'some_unique_key1' => { 'Submitted Date' => 'submitted_date1', 'Metadata' => 'meta_data_1' } };

Replies are listed 'Best First'.
Re^3: Populating a hash-ref from multiple arrays with slice?
by FreeBeerReekingMonk (Deacon) on Apr 16, 2015 at 21:10 UTC
    Rate netWallah hashref toolic jeffa netWallah 324041/s -- -16% -16% -35% hashref 387028/s 19% -- -0% -22% toolic 387777/s 20% 0% -- -22% jeffa 497471/s 54% 29% 28% --
    Note that Jeffa's code is faster because it uses HoA, and not HoH. if you then use constants to access 0 and 1 it could be the way to go.