有没有办法在perl中创建两个数组的哈希?

Ste*_*hen 1 arrays perl hash

我是Perl的新手,所以我遇到了一些麻烦.说我有两个数组:

@num = qw(one two three);
@alpha = qw(A B C);
@place = qw(first second third);
Run Code Online (Sandbox Code Playgroud)

我想创建一个哈希,第一个元素作为键,剩余的值作为数组,无论它们是3还是3000个元素

所以散列本质上是这样的:

%hash=(
    one => ['A', 'first'],
    two => ['B', 'second'],
    third => ['C', 'third'],
);
Run Code Online (Sandbox Code Playgroud)

Bor*_*din 6

use strict;
use warnings;

my @num   = qw(one two three);
my @alpha = qw(A B C);
my @place = qw(first second third);

my %hash;
while (@num and @alpha and @place) {
  $hash{shift @num} = [ shift @alpha, shift @place ];
}

use Data::Dump;
dd \%hash;
Run Code Online (Sandbox Code Playgroud)

产量

{ one => ["A", "first"], three => ["C", "third"], two => ["B", "second"] }
Run Code Online (Sandbox Code Playgroud)