なお、配列には、文字列が入る場合もあります。
宜しくお願い致します。
データ
@test = (1,1,1,2,1,2,3,3,4,0);
結果
@test = (4,0);
# う~ん、美しくない・・・orz
#!/usr/bin/perl
use strict;
use warnings;
my @res;
my @test = (1,1,1,2,1,2,3,3,4,0);
for my $t (@test) {
push(@res, $t) if (grep(/^$t$/, @test) <= 1);
}
print join(",", @res). "\n";
__END__
my @test = (1,1,1,2,1,2,3,3,4,0); my %count = (); $count{$_}++ for @test; @test = grep { $count{$_} == 1 } @test;
こんなところ?
がんばればもうちょっときれいに書けるかも。
my @test = (1,1,1,2,1,2,3,3,4,0) ; my %count ; foreach (@test) {$count{$_}++ ;} @test = grep {$count{$_} < 2} @test ; print @test ;
コメント(0件)