++ , --
配合只希计数,判断之前已出现过的元素:
#! /usr/bin/perl
my @people = qw (able Fred Fred barney bamm-bamm wilma dino barney betty pebbles );
my %seen;
foreach (@people) {
print "I've seen you somewhere before, $_!\n"
if $seen{$_}++;
}
因为barney出现了再次,所给输出为:
I've seen you somewhere before, barney!
阅读(317) | 评论(0) | 转发(0) |