in reply to Yet Another Half Perl Half mySQL Question
Table Creation :
Then INSERT rows. And later, to access :$sql = "CREATE TABLE depend (\ usedby VARCHAR(80) NOT NULL ,\ uses VARCHAR(80) NOT NULL \ )"; $dbh->do($sql);
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.$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;
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
|
|---|