Portál AbcLinuxu, 22. prosince 2025 06:30
@pole = ( [1, 2], [3, 4], [1, 2], [2, 2] );Co má být na výstupu?
perldoc -q duplicate
@pole = (
[1, 2],
[3, 4],
[1, 2],
[2, 2]
);
my %h;
@pole = grep {$h{join(":",@$_)}++ == 0} @pole;
use Data::Dumper;
print Dumper(\@pole);
uniq_by s CPAN by to šlo takhle:
use warnings;
use strict;
use 5.010;
use Data::Dumper;
sub uniq_by(&@)
{
my $code = shift;
my %present;
return grep {
my $key = $code->( local $_ = $_ );
!$present{$key}++
} @_;
}
my @x = ([1, 1], [2, 2], [3, 5], [2, 2], [3,4], [2,1], [1,1]);
say Dumper( uniq_by { "@$_" } @x);
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.