我有一个这样的数组:
my @arr = ("Field3","Field1","Field2","Field5","Field4");
现在我使用地图如下,其中/ DOSOMETHING /是我正在寻找的答案。
my %hash = map {$_ => **/DOSOMETHING/** } @arr
现在我需要哈希如下所示:
Field3 => 0 Field1 => 1 Field2 => 2 Field5 => 3 Field4 => 4
任何帮助?
解决方法
%hash = map { $arr[$_] => $_ } 0..$#arr; print Dumper(\%hash) $VAR1 = { 'Field4' => 4,'Field2' => 2,'Field5' => 3,'Field1' => 1,'Field3' => 0 };