Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Yet Another Half Perl Half mySQL Question

by Brovnik (Hermit)
on Jul 06, 2001 at 17:49 UTC ( #94462=note: print w/ replies, xml ) Need Help??


in reply to Yet Another Half Perl Half mySQL Question

This is what I used for a module written recently.

Table Creation :

$sql = "CREATE TABLE depend (\ usedby VARCHAR(80) NOT NULL ,\ uses VARCHAR(80) NOT NULL \ )"; $dbh->do($sql);
Then INSERT rows. And later, to access :
$sql = "SELECT usedby FROM depend where uses=$name"; $aref = $dbh->selectall_arrayref($sql); my @uses = map {$_->[0]} @$aref; $sql = "SELECT uses FROM depend where usedby=$name"; $aref = $dbh->selectall_arrayref($sql); my @usedby = map {$_->[0]} @$aref;
Note that the table is created without unique IDs or primary keys since this is a many-to-many relationship. One of the columns could be an IP address in your case.

For the pedants, there is replication of the name in the columns, but the duplication is outweighed by the ease of access (see how easy in lines of code it is to retrieve a list of names) and reduction in complexity by not having a name-to-id mapping.

BTW, the previous iteration of the module used a single entry in another table and used join/split, which is quicker, but less elegant in DB terms.

If you need raw speed, use Perl to do the split, if you want it cleaner and more DBish, use a table as above.

Full module is Depend::Module
--
Brovnik


Comment on Re: Yet Another Half Perl Half mySQL Question
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-10-26 01:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls