in reply to Object Oriented Perl - very basic guide
The reason that's useful, is because if I write a module for you to use - then all you need to know is how to run the internal code, and don't have to worry about what goes on inside.The same can be said of any module whether it be object oriented or not e.g File::Find.
Some reasons that objects are useful:
You can write code like that whether your database is MySQL, PostgreSQL or any other supported by DBI. Each DBD::* driver module has methods implementing the familiar DBI interface whilst also encapsulating the details of how to communicate with a specific database.$sth = $dbh->prepare(q{ SELECT region, sales FROM sales_by_region }); $sth->execute; my ($region, $sales); # Bind Perl variables to columns: $rv = $sth->bind_columns(\$region, \$sales); # you can also use Perl's \(...) syntax (see perlref docs): # $sth->bind_columns(\($region, $sales)); # Column binding is the most efficient way to fetch data while ($sth->fetch) { print "$region: $sales\n"; }
|
|---|