How to create a DBM database in Perl

T

Topher

Hi,

I would appreciate some help with this. I am trying to create an admin
section for my local table tennis (yes, it's a manly sport I know...)
site and am having trouble creating any databases.

The code I have for doing this is as follows:

## write

dbmopen (%clubs, $const_database_path."clubs", 0666);

die("club id already exists!") if ($clubs{$club_id} ne "");

$clubs{$club_id} = $club_name."§".$club_short_name."§".$club_location1."§".$club_location2."§".$club_location3."§".$club_location4."§".$club_postcode."§".$club_map_href."§".$club_map_text."§".$club_website_href."§".$club_notes."§".$club_secretary_name."§".$club_secretary_add1."§".$club_secretary_add2."§".$club_secretary_add3."§".$club_secretary_add4."§".$club_secretary_postcode."§".$club_secretary
home_tel."§".$club_secretary_mobile_tel."§".$club_secretary_work_tel."§".$club_secretary_email;


dbmclose (%clubs);


I'm not too hot on this Perl business and am basically winging it with
a bit of help from a mate every now and again, but can't seem to find
anything that shows why this is not happening. I have a file
'mkttl.conf', which is linked to earlier on in the script using
require("mkttl.conf");

In mkttl.conf I define $const_database_path as
$ENV{"SITE_ROOT"}."\mkttl_concept\databases\"

I have created the databases directory, so there should be no problems
there.

I'm not getting error messages, it's just not working - annoying as
hell!

If it's any use I am using Xitami, which is the server that I have
downloaded to test scripts on before I upload stuff.

Thanks very much, if you need any more info please ask!
 
J

joeri

Topher said:
Hi,

I would appreciate some help with this. I am trying to create an admin
section for my local table tennis (yes, it's a manly sport I know...)
site and am having trouble creating any databases.

The code I have for doing this is as follows:

## write

dbmopen (%clubs, $const_database_path."clubs", 0666);

die("club id already exists!") if ($clubs{$club_id} ne "");

$clubs{$club_id} = $club_name."§".$club_short_name."§".$club_location1."§".$club_location2."§".
$club_location3."§".$club_location4."§".$club_postcode."§".$club_map_href."§
".$club_map_text."§".$club_website_href."§".$club_notes."§".$club_secretary_
name."§".$club_secretary_add1."§".$club_secretary_add2."§".$club_secretary_a
dd3."§".$club_secretary_add4."§".$club_secretary_postcode."§".$club_secretar
y
home_tel."§".$club_secretary_mobile_tel."§".$club_secretary_work_tel."§".$cl
ub_secretary_email;


dbmclose (%clubs);

What doesn't seem to be working for you? What do you expect this code to do?

J
 
G

Gunnar Hjalmarsson

Topher said:
I am trying to create an admin section for my local table tennis
(yes, it's a manly sport I know...) site and am having trouble
creating any databases.

The code I have for doing this is as follows:

## write

dbmopen (%clubs, $const_database_path."clubs", 0666);

Should better be:

dbmopen (%clubs, $const_database_path."clubs", 0666)
or die "Couldn't open database\n$!";

or something like that. That will result in an error message if e.g.
$const_database_path does not contain a valid path (which I doubt it
does, see below).
die("club id already exists!") if ($clubs{$club_id} ne "");

$clubs{$club_id} =
$club_name."§".$club_short_name."§".$club_location1."§".
$club_location2."§".$club_location3."§".$club_location4."§".
$club_postcode."§".$club_map_href."§".$club_map_text."§".
$club_website_href."§".$club_notes."§".$club_secretary_name."§".
$club_secretary_add1."§".$club_secretary_add2."§".
$club_secretary_add3."§".$club_secretary_add4."§".
$club_secretary_postcode."§".$club_secretaryhome_tel."§".
$club_secretary_mobile_tel."§".$club_secretary_work_tel."§".
$club_secretary_email;

Without knowing anything about the rest of your application, including
how all those variables are populated, I have a feeling that your data
structure leaves room for improvements. :) But if you want advice in
that respect, you'd better explain more about what you are actually doing.

I have a file 'mkttl.conf', which is linked to earlier on in the
script using require("mkttl.conf");

In mkttl.conf I define $const_database_path as
$ENV{"SITE_ROOT"}."\mkttl_concept\databases\"

That does certainly not seem to be correct. Is there really a
$ENV{"SITE_ROOT"} variable? And using backslashes within doublequotes
does likely result in something else but what you expect.

I would _guess_ that this is what you should have in mkttl.conf:

$const_database_path =
$ENV{DOCUMENT_ROOT} . '/mkttl_concept/databases/';
 
B

Ben Morrow

I'm not getting error messages, it's just not working - annoying as
hell!

When you do start getting error messages, you may find the line

use CGI::Carp qw/fatalsToBrowser/;

at the top useful.

Ben
 
S

Steve

Hi, ............
I'm not too hot on this Perl business and am basically winging it with
.....

Well I am not playing, but I have to say I find this game very
entertaining. It seems to be happening quite often that someone posts
a merest tease of a hint of what they are trying to do and some
incomprehensible garbled code and everyone tries to guess the task and
the existing errors and then write the code that they think might
address the problem.

I am quite genuinely in awe of the skilled players.

Steve
 
T

Topher

....

Well I am not playing, but I have to say I find this game very
entertaining. It seems to be happening quite often that someone posts
a merest tease of a hint of what they are trying to do and some
incomprehensible garbled code and everyone tries to guess the task and
the existing errors and then write the code that they think might
address the problem.

I am quite genuinely in awe of the skilled players.

Steve

Thanks people who have tried to help. I feel stupid to have forgotten
the die statement now!

Steve, you will notice at the bottom of my post 'Thanks very much, if
you need any more info please ask', since I wasn't sure what other
information I should give.
 
C

Chris Mattern

Topher said:
Thanks people who have tried to help. I feel stupid to have forgotten
the die statement now!

Steve, you will notice at the bottom of my post 'Thanks very much, if
you need any more info please ask', since I wasn't sure what other
information I should give.

If you read the guidelines, you'd *know* what info to give. Generally, you
should give an example Perl program that is as small as you can make it but
still produces the problem, what you expect this program to do, and what is
*does* do instead.

Chris Mattern
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top