use strict; use DBI; use SetDB; # Must turn off no strict subs so I can use magical barewords # This is certainly not required for using this module no strict 'subs'; # Okay, first we set up our DBI connection my $dbi = DBI->connect('DBI:mysql:database=setdb_test;host=localhost', 'setdb', 'setdb'); # Now we set up our schema (see website for the file) use vars qw( $schema ); do 'schema.pl'; # This creates our SetDB database my $db = new SetDB($dbi, $schema); # Lets get a set of people and their books my $people = $db->newSet(person, [book]); # Now loop through and print out each person while(my $person = $people->fetchNext()) { print "Name: $person->{name}\n"; # This is the set of books which that person has my $books = $person->{book}; # Lets go ahead and print all of their books while(my $book = $books->fetchNext()) { print " Book: $book->{title}\n"; # Demonstrate updates by adding ' sucks!' to the book's title $book->{title} .= ' sucks!'; } } #### awwaiid@feline:~/projects/perl/setdb$ ./setdb_demo.pl Name: Bob Book: How to Take Over the World! Book: When I Went Shopping Name: Joe Name: Frank Book: How to Take Over the World! sucks! Book: How to build a turtle Book: Turtle Soup awwaiid@feline:~/projects/perl/setdb$ ./setdb_demo.pl Name: Bob Book: How to Take Over the World! sucks! sucks! Book: When I Went Shopping sucks! Name: Joe Name: Frank Book: How to Take Over the World! sucks! sucks! sucks! Book: How to build a turtle sucks! Book: Turtle Soup sucks!