perl - Perl 中的 HashMap

标签 perl hash higher-order-functions

是否有与 map 等效的哈希值?

my %new_hash = hash_map { new_key($a) => new_val($b) } %hash;

我知道我可以循环按键。

最佳答案

List::Pairwise声称完全实现了该语法 - 请参阅 mappgrepp。不过我还没用过。

此外,您也可以这样做

%new_hash = map { new_key($_) => new_value($hash{$_}) } keys %hash; 

我承认,如果 %hash 确实是 $deeply->{buried}->{hash},那么看起来会更笨拙。我更喜欢使用 $temp = ...;在这种情况下,映射 {...} 键 %$temp

关于perl - Perl 中的 HashMap ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5769348/

相关文章:

在C中计算结构的哈希值

c++ - 如何在 O(n) 运行时间内从答案中删除重复项?

php - 多版本哈希密码

haskell - Haskell 中 scanl 和 scanr 的递归定义

javascript - 在组件渲染中调用高阶组件

regex - 使用 Perl 自动进行形态标记

java - 使用正则表达式解析文本文件

perl - 如何在 perl 中获取 'milliseconds' 作为时间的一部分?

perl - 为什么遵循 XPath 语句返回所有 "a"元素?

functional-programming - VHDL 或 Verilog 中的高阶函数