我知道我可以写一些类似的东西,但内置会很方便.
琐碎的例子:
我的%h; @test的%h {$_};
my %h is Bag = @test;
或者如果你只想强迫:
my $bag = @test.Bag;
在任何一种情况下,您都可以像任何普通的哈希一样使用该对象.
# show sorted with most frequent first say "{.key} seen {.value} times" for %h.sort: -*.value