App-Sets
view release on metacpan or search on metacpan
lib/App/Sets/Sort.pm view on Meta::CPAN
seek $ifh, 0, SEEK_SET;
return $ifh;
}
sub _flush_to_temp {
my ($records) = @_;
my $tfh = tempfile(UNLINK => 1);
my $previous;
for my $item (sort @$records) {
next if defined($previous) && $previous eq $item;
print {$tfh} $item, $INPUT_RECORD_SEPARATOR;
}
@$records = ();
seek $tfh, 0, SEEK_SET;
return $tfh;
}
sub _compact {
my ($fhs) = @_;
return if @$fhs == 1;
lib/App/Sets/Sort.pm view on Meta::CPAN
# iterate until all contributors are exhausted
while (scalar keys %its) {
# select the best (i.e. "lower"), cleanup on the way
my ($fk, @keys) = keys %its;
my $best = $its{$fk}[1];
for my $key (@keys) {
my $head = $its{$key}[1];
$best = $head if $best gt $head;
}
print {$ofh} $best, $INPUT_RECORD_SEPARATOR;
# get rid of the best in all iterators, cleanup on the way
KEY:
for my $key ($fk, @keys) {
my $head = $its{$key}[1];
while ($head eq $best) {
$head = readline $its{$key}[0];
if (defined $head) {
chomp($its{$key}[1] = $head);
}
( run in 0.524 second using v1.01-cache-2.11-cpan-64827b87656 )