CDB_File-Generator
view release on metacpan or search on metacpan
lib/CDB_File/Generator.pm view on Meta::CPAN
=head2 finish
Finish ends of the cdb creation. First it closes the output temporary
file, then it sorts it to another file and finally it calls C<cdbmake>
to complete the creation job.
In the current implementation this uses C<sort -u> and deletes repeats of
the same key with the same value.
In order to increase database portability, by default all sorting is
done in the 'C' locale, even if the current program is working in
another locale. This is "the right thing" in many cases. Where you
are dealing with real word keys it won't be the right thing. In this case, use the locale function to set the locale.
=cut
sub locale ($) {
my $self=shift;
my $locale=shift;
$self->{locale}=$locale;
}
sub finish ($) {
my $self=shift;
close $self->{"fh"};
{
local $ENV{LC_ALL};
if ($self->{locale}) {
$ENV{LC_ALL}=$self->{locale};
} else {
$ENV{LC_ALL}='C';
}
system 'sort' , '-u', '-o' ,$self->{"tmpsortfile"} , $self->{"tmpoutfile"};
}
my $fh = new IO::File $self->{"tmpsortfile"}
or die "couldn't open sorted output file";
my $cdbmakeout = new IO::File ( '|cdbmake ' . $self->{"cdbfile"}
( run in 1.042 second using v1.01-cache-2.11-cpan-ceb78f64989 )