LogoPhly, boy, phly
the weblog and site of Matthew Weier O'Phinney

Tuesday, January 20. 2004

Perl Cookbook, 2nd Edition

Tonight was Papa night, which meant that I got to look after Maeve while Jen worked late doing a group at work. Last week, Maeve and I established that Papa Night would always include going to the bookstore, which means Barnes & Noble in South Burlington.

Last week, Maeve was perfectly content to look at books by herself, and didn't want me interfering, so I decided this week to grab a book for myself to peruse while she was busy. It didn't work as I intended -- Maeve saw that I wasn't paying full attention to her, and then demanded my attention -- but I was able to look through some of the new items in the second edition of The Perl Cookbook.

Among them were:

  • Setting up both an XML-RPC server and client, using SOAP::Lite
  • Setting up both a SOAP-RPC server and client, using SOAP::Lite and other modules; I could have used this in ROX::Filer to communicate with ROX instead of using the filer's RPC call.
  • Better coverage of DBI (it actually covered it!):
    • When you expect only a single row, this is a nice way to grab it:
      $row = $dbi->selectrow_(array|hash)ref($statement)
                      
    • This is a great way to grab a bunch of columns from a large resultset:
                          $results = $dbi->selectall_hashref($sql);
                          foreach $record (keys(%{$results})) {
                              print $results->{$record}{fieldname};
                          }
                      
    • This one is nice for a large resultset from which you only want one column:
                          $results = $dbi->selectcol_arrayref($sql);
                          foreach $result (@{$results}) {
                              print $result;
                          }
                      
    • If you need to quote values before inserting them, try:
                          $quoted = $dbi->quote($unquoted);
                          $sql = "UPDATE table SET textfield = $quoted";
                      
    • If you need to check for errors, don't check with each DBI call; instead, wrap all of them in an eval statement:
                          eval {
                              $sth = $dbi->prepare($sql);
                              $sth->do;
                              while ($row = $sth->fetchrow_hashref) {
                                  ...
                              }
                          }
                          if ($@) {
                              print $DBI::errstr; 
                          }
                      
  • Coverage of templating, including Text::Template (very interesting!)
  • Whole new chapters on mod_perl and XML (including DOM!) which I didn't really even get to peruse.
  • autouse pragma: if you use:
    use autouse Module::Name;
    perl will use the module at runtime instead of compiletime; basically, it only uses it if it actually needs it (i.e., if it encounters code that utilizes functionality from that module). It's a good way to keep down on the bloat -- I should use this with librox-perl, and possibly with CGI::App.
Posted by Matthew Weier O'Phinney in Personal at 22:34 | Comments (0) | Trackbacks (0)

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

No comments

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 
  • Home
  • Resume
  • Blog
  • Phly PEAR Channel
  • Contact Me
  • About this site

ZCE

Zend Education Advisory Board Member

Add to Technorati Favorites

Calendar

Back November '08 Forward
Mon Tue Wed Thu Fri Sat Sun
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Quicksearch

Links

  • PHLY - PHp LibrarY
  • Paul M. Jones
  • Mike Naberezny
  • Shahar Evron
  • Planet PHP
  • Zend Where I now work
  • Garden.org Where I once worked

Archives

November 2008
October 2008
September 2008
Recent...
Older...

Categories

XML Linux
XML Personal
XML Aikido
XML Family
XML Programming
XML Dojo
XML Perl
XML PHP

All categories

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Show tagged entries

xml best practices
xml books
xml conferences
xml dojo
xml dpc08
xml file_fortune
xml linux
xml mvc
xml oop
xml pear
xml personal
xml php
xml phpworks08
xml programming
xml ubuntu
xml vim
xml webinar
xml zendcon
xml zendcon08
xml zend framework
© 2004 - present, Matthew Weier O'Phinney
matthew-web <at> weierophinney.net