Perl - Array to Hash

C1 C2 C3 C4 C5
11 12 13 14 15
21 22 23 24 25

my $data = [
            [11,12,13,14,15],
            [21,22,23,24,25]
           ];
my $column_ids = ["C1", "C2", "C3", "C4", "C5"];

# %h - {'C1'=>'x1', 'C2'=>'x2', 'C3'=>'x3', 'C5'=>'x4', 'C5'=>'x5'}
my $results = [map { my %h; @h{ @$column_ids } = split(",", $_); \%h } @$data];


results得到一个hash数组
results[0] - {'C1'=>'11', 'C2'=>'12', 'C3'=>'13', 'C5'=>'14', 'C5'=>'15'}
results[1] - {'C1'=>'21', 'C2'=>'22', 'C3'=>'23', 'C5'=>'24', 'C5'=>'25'}

http://stackoverflow.com/questions/95820/in-perl-how-do-i-create-a-hash-whose-keys-come-from-a-given-array

你可能感兴趣的:(array)