Assuming you are saying you need to read/write to a dbm I would suggest looking at DBM and DB::File (cpan)
Otherwise if it is a Flat file of text please give us an example of the data you need to parse
heres simple module I wrote for a project to ease reading/writeing to a DB::File. It uses storable so you can store structures in the dbfile easily.
package easydb;
use strict;
use DB_File;
use Storable qw(freeze thaw) ;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = qw(&db_open &db_close &db_store &db_fetch &db_keys);
@EXPORT_OK = qw(&db_open &db_close &db_store &db_fetch &db_keys);
my %db ;
sub db_open
{
my $dbfile = shift ;
tie(%db, "DB_File", $dbfile)
or die "Can't open $dbfile: $!";
return \%db ;
}
sub db_close
{
untie %db ;
}
sub db_store
{
my ($key, $hashref) = @_ ;
$db{$key} = freeze($hashref);
return $key;
}
sub db_fetch
{
my ($key) = shift;
my $ref = thaw($db{$key}) ;
return $ref ;
}
sub db_keys
{
return keys %db ;
}
1;
and heres an example of how it is used in a program:
#!/usr/bin/perl
use lib('.');
use warnings;
use easydb ;
use Data::Dumper;
use strict ;
my $dbfile = "some.db" ;
db_open($dbfile) ;
my %legend = (
"asap.cgi" => "Journal ASAPS",
"abstract" => "Journal Abstract",
"query" => "Journal Query",
"cen" => "CEN Report",
"preprint" => "Preprint Report",
"reagent2000" => "Reagent Report",
"article.cgi" => "Current Journal Articles",
"archive.cgi" => "Article Archive"
) ;
db_store ("legend",\%legend);
my $legend = db_fetch("legend");
foreach my $key (sort keys %$legend )
{
print "$$legend{$key}\n";
}
db_close() ;
exit ;
Not a lot of comments, but it may help ya out there
|