Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
本质上,我想命名列表的元素。
我可以做这个:
($hash{'foo'}, $hash{'bar'}, $hash{'baz'}) = listmaker;
但是如果列表中有很多元素,那会变得相当冗长。
有没有更短的方法只命名哈希一次?也许对此有一些变化:
%hash = ("foo" => "abc", "bar" => "def", "baz" => "ghi");
但是来自函数的值listmaker?我在设想某种map咒语。
listmaker
map
使用哈希切片:
@hash{'foo', 'bar', 'baz'} = listmaker
或者
@hash{qw( foo bar baz )} = listmaker