6 use MLDBM qw(DB_File Storable);
9 $MLDBM::DumpMeth=q(portable);
11 # given an index and a set of stubs, populate the index with the stubs
13 my ($index,@stubs) = @ARGV;
15 my $index_new = $index.'.new';
16 my $tied_index = open_index($index_new);
17 populate_index($tied_index,\@stubs);
18 close_index($tied_index,$index_new,$index);
20 # open and create a tied index
24 tie %db, "MLDBM", $index, O_CREAT|O_RDWR, 0664
25 or die "tie $index: $!";
29 # populate the index with the given stubs
31 my ($tie,$stubs) = @_;
32 for my $stub (@{$stubs}) {
33 my $fh = IO::File->new($stub,'r');
35 my $file_contents = <$fh>;
36 my @stub_results = eval $file_contents;
38 die "Stub $stub failed with error $@";
40 my %stub_results_to_add;
41 if (@stub_results == 1 and
42 ref($stub_results[0]) and
43 ref($stub_results[0]) eq 'ARRAY') {
44 @stub_results = @{$stub_results[0]};
46 if ((@stub_results % 2) == 0 and
47 not ref($stub_results[0])
49 %stub_results_to_add = @stub_results;
51 for my $stub_result (@stub_results) {
52 next unless ref($stub_result);
53 next unless ref($stub_result) eq 'HASH';
54 %stub_results_to_add = (%stub_results_to_add,
58 for my $sr (keys %stub_results_to_add) {
59 $tie->{$sr} = $stub_results_to_add{$sr};
66 my ($tie,$index_new,$index) = @_;
68 rename($index_new,$index);