March 2002 Perl Hardware Store 17

3. Adding a new Method to a Package

         my $sth = $dbh->prepare($query)
           or die "Couldn't prepare '$query': " . $dbh->errmsg;
         $sth->execute(...)
           or die "Couldn't execute '$query': " . $sth->errmsg;
         my @data;
         while (my $rec = $sth->fetchrow_hashref) {
           push @data, [@$rec];
         }
         $sth->finish;
         # Do something with @data
        @data = $dbh->myquery($query, ...);  # dies if necessary
        # Do something with @data


Next Copyright © 2002 M-J. Dominus