in reply to Re: Perl OOP variables
in thread Perl OOP variables

I need to able to access the methods like this though.
There is a table in the database named MEMBERS. So we insert something in to the table like so.
my $member_id = MEMBERS->insert(\%ins_hash);
How would I write the module without the need for a constructor?

BMaximus

Replies are listed 'Best First'.
Re: Re: Re: Perl OOP variables
by Brovnik (Hermit) on May 31, 2001 at 10:24 UTC
    Use Tie::DBI. Example:
    use Tie::DBI; tie %db,Tie::DBI,{db => "mysql:Perlmonks", table => "Reputation", key => "nodeid", user => $def_dbuser, password => $def_dbpw, CLOBBER => 3};
    You can call it %Reputation if you want.

    Then, you can access the table directly and intuitively.

    # # Find all the new, deleted and changed entries # And find the longest title # calculate min and max reputations and total # Just want to make one pass through all of the list # for (keys %db) { my $type = $db{$_}->{type}; next if $type eq 'X'; push (@newnodes, $_) if $type eq 'N'; push (@deletednodes, $_) if $type eq 'D'; push (@changednodes, $_) if $type eq 'C'; $longest_title = max ($longest_title, length ($db{$_}->{title})) +; $total += $db{$_}->{reputation}; $repmax = max ($repmax, $db{$_}->{reputation}); $repmin = min ($repmin, $db{$_}->{reputation}); }
    This sample from my rewrite of luke_repwalker.pl, which I have tweaked to use Tie::DBI.
    --
    Brovnik