Dr.*_*ust 2 arrays perl hash reference
我正在寻找一种更优雅的方式来创建一个包含我从配置文件中读取的列表的哈希.这是我的代码:
read_config($config_file => my %config);
my $extension_list_reference = $config{extensions}{ext};
my @ext;
# Store each item of the list into an array
for my $i ( 0 .. (@$extension_list_reference - 1) ) {
    $ext[$i] = $extension_list_reference->[$i];
}
# Create hash with the array elements as the keys
foreach my $entry (@ext) {
    $extensions{$entry} = "include";
 }   
谢谢.
尝试使用地图:http: //perldoc.perl.org/functions/map.html
以下是您的新代码应如下所示:
my %extensions = map { $_ => "include" } @{ $config{extensions}{ext} };