以下我使用$size = keys %prices;
来获取哈希表中条目的总数。然而,在下面的例子中是否有一种方法可以获取价格低于$4的条目数量?
use strict;
my %prices;
# create the hash
$prices{'pizza'} = 12.00;
$prices{'coke'} = 1.25;
$prices{'sandwich'} = 3.00;
$prices{'pie'} = 6.50;
$prices{'coffee'} = 2.50;
$prices{'churro'} = 2.25;
# get the hash size
my $size = keys %prices;
# print the hash size
print "The hash contains $size elements.\n";