Changes between Version 6 and Version 7 of Perl
- Timestamp:
- 08/29/06 14:50:08 (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Perl
v6 v7 272 272 print $hash{(HOGE)}, "\n"; 273 273 }}} 274 275 == ハッシュ関連 == 276 === ハッシュが格納されている配列中で,ハッシュの中のある特定のキーの値が同じものを削除する === 277 {{{ 278 #!perl 279 sub keygrep($$) { 280 my $array = shift; 281 my $key = shift; 282 my %seen = (); 283 my @res = (); 284 285 @res = sort { $a->{$key} cmp $b->{$key} } @{$array}; 286 @res = grep(!$seen{$_->{$key}}++, @res); 287 288 return \@res; 289 } 290 }}} 291 * ([{a=>1, b=>2}, {a=>2, b=>3}, {a=>1, b=>3}], "a") が [{a=>1, b=>2}, {a=>2, b=>3}] で返る.