Perlfect Solutions
 

[Perlfect-search] data dump script (and xml)

will will@spanner.org
Fri, 27 Apr 2001 00:12:53 +0100
hello

i've been spending some time adding data types and whatnot to the 
search. most of that will be of no interest to anyone, because it's 
all to do with my increasingly baroque content-management system and 
its proliferation of xml files. two things came up:

the way perlfect works is really very good for indexing xml files in 
a simple way: all you have to do is change the parsing for title and 
description and body to the relevant xml fields and you get a nice, 
if limited, low-overhead free-text search of your xml data. no expat, 
no nasty anything. very impressed. is that something that should be 
developed? might be able to help, if so.

meanwhile, i needed to see the contents of the database files for the 
fields i was adding, so i chopped up the search script to make this 
ugly little data dumper cgi. It sits in the search directory and 
takes two parameters: database name as db (eg db=titles) and record 
id as id (eg id=9, if you don't want the whole lot dumped on you). 
it's not very big or very clever, and you certainly don't want to 
leave it lying around when you've finished with it. it's pasted in 
below. i hope someone finds it useful.

any improvements very welcome.

best

will



#!/usr/local/bin/perl
# data_dump.pl
# made with perlfect's search.pl and an axe

use Fcntl;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

{
   $0 =~ /(.*)(\\|\/)/;
   push @INC, $1 if $1;
}

my $db_package = "";
package AnyDBM_File;
@ISA = qw(DB_File) unless @ISA;
foreach my $isa (@ISA) {
   if( eval("require $isa") ) {
     $db_package = $isa;
     last;
   }
}
if( $db_package  ne 'DB_File' ) {
   die "*** The DB_File module was not found on your system.";
}

package main;
require 'conf.pl';

$|=1;

my $query = new CGI;
$query->import_names('input');
my %datafiles = (
        docs => $DOCS_DB_FILE,
        sizes => $SIZES_DB_FILE,
        desc => $DESC_DB_FILE,
        content => $CONTENT_DB_FILE,
        titles => $TITLES_DB_FILE,
        terms => $TERMS_DB_FILE
        );
my $dbfile = $datafiles{$input::db};
die ('invalid database file specified') unless $dbfile;

my %data;
tie %data, $db_package, $dbfile, O_RDONLY, 0755 or die "Cannot open 
$dbfile: $!";

print "content-type:text/html\n\n";
print "<html><head><title>Contents of $dbfile</title></head><body>";
print "<p>Using $db_package...</p>\n";
print "<h2>Contents of $dbfile:</h2>\n<p>";
if ($input::id) {
        print "$input::id = $data{$input::id}<br>\n";
} else {
        print "$_ = $data{$_}<br>\n" for (keys %data);
}
print "</p></body></html>";
exit;




-- 











pgpkey: http://www.spanner.org/keys/will.txt