Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Lady_EZDB

by Steeeeeve (Initiate)
on Feb 06, 2001 at 12:28 UTC ( [id://56636]=sourcecode: print w/replies, xml ) Need Help??
Category: Utillities
Author/Contact Info Charles Prichard (Steeeeeve) greentv@paulbunyan.net
Description: A simple way to read a one record DB file.

Immediate usage is for a config file of a site wrapper.

Use EZDB to manage the settings and this module to read the file in your initialization method.
package Lady_EZDB;

use strict;

#################################################
#  Sub new                                  #
#################################################
#################################################
#       PUBLIC Subroutine                       #
#################################################
sub new ($;$){

    my $class = shift;

    my $self = {};
    
    bless $self, ref $class || $class;
    
    $self->{index_path} = undef;
    $self->{sep} = undef;
    $self->{lady_time} = undef;
    $self->{header} = undef;
    $self->{data} = undef;
    
    $self->{TABLE} = {};

    $self->init(@_);
        
    return $self;

}
sub init($;$){
    
    my $self = shift;

    $self->{index_path} = shift;
    
    if ($_[0]){$self->{sep}= shift;}else{$self->{sep}="|";}
    
    use Lady::Lady_DATE;

    my $TIME = new Lady_DATE;

    $self->{lady_time} = $TIME->lady_time();

return;
}
#################################################
#       Sub get_EZDB_table                     #
#################################################
#################################################
#       PUBLIC Subroutine                       #
#################################################
sub get_EZDB_table (){

      my $self = shift;

      open(INDEXFILE, "$self->{index_path}") || $self->file_open_error
+("$self->{index_path}","Read Index",__FILE__,__LINE__);

      $self->{header} = <INDEXFILE>;     #READ first line.
      
      $self->{data} = <INDEXFILE>;    #READ data line.
      
      close(INDEXFILE);


      my $sep = $self->{sep}; # OOP BUGFIX 

      my @keys = split(/\$sep/,$self->{header});
      my @values = split(/\$sep/,$self->{data});
      
      my $x = 0;
      foreach $_ (@keys){
          
          $self->{TABLE}{$_} = $values[$x];

                $x++;

      
      }

      return $self->{TABLE};
}
#################################################
#       Sub file_open_error                 #
#################################################
#################################################
#       PRIVATE Subroutine                      #
#################################################
sub file_open_error($$$$){
    
    my $self = shift;

      my $bad_file = shift;
      my $script_section = shift;
      my $this_file = shift;
      my $line_number = shift;

    use CGI_lib;

    my $CGI = new CGI_lib();

    $CGI->CgiDie ("I am sorry, but I was not able to access $bad_file 
+in the
            $script_section routine of $this_file at line number $line
+_number.
            Would you please make sure the path is correctly defined i
+n
            SETUP_dB and that the permissions are correct. $!")

} # End of Sub "file_open_error"
 
1;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://56636]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-23 11:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found