How to create a DBM database in Perl

Discussion in 'Perl Misc' started by Topher, Nov 27, 2003.

  1. Topher

    Topher Guest

    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!
     
    Topher, Nov 27, 2003
    #1
    1. Advertising

  2. Topher

    joeri Guest

    "Topher" <> wrote in message
    news:...
    > 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
     
    joeri, Nov 27, 2003
    #2
    1. Advertising

  3. Topher wrote:
    > 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.

    <snip>

    > 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/';

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Nov 27, 2003
    #3
  4. Topher

    Ben Morrow Guest

    (Topher) wrote:
    > 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

    --
    I've seen things you people wouldn't believe: attack ships on fire off the
    shoulder of Orion; I've watched C-beams glitter in the darkness near the
    Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
    Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|
     
    Ben Morrow, Nov 27, 2003
    #4
  5. Topher

    Steve Guest

    (Topher) wrote in message news:<>...
    > 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
     
    Steve, Nov 27, 2003
    #5
  6. Topher

    Topher Guest

    (Steve) wrote in message news:<>...
    > (Topher) wrote in message news:<>...
    > > 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


    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.
     
    Topher, Nov 28, 2003
    #6
  7. Topher wrote:
    > (Steve) wrote in message news:<>...
    >
    >> (Topher) wrote in message news:<>...
    >>
    >>>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

    >
    >
    > 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
     
    Chris Mattern, Nov 28, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Johnson
    Replies:
    0
    Views:
    1,276
    Matt Johnson
    Aug 8, 2003
  2. Topher
    Replies:
    1
    Views:
    1,130
    Gunnar Hjalmarsson
    Jan 21, 2004
  3. Colvin
    Replies:
    3
    Views:
    168
    Colvin
    Dec 30, 2003
  4. OttawaTrade

    How to stop DBM/Perl crashing servers?

    OttawaTrade, Sep 13, 2005, in forum: Perl Misc
    Replies:
    9
    Views:
    518
    Keith Keller
    Sep 13, 2005
  5. Replies:
    4
    Views:
    160
    Steve C
    Feb 26, 2010
Loading...

Share This Page