-- Robert <[EMAIL PROTECTED]>

This is my hash structure:

"Veterans Day" => {
    date    => '20051111',
    type    => 'US',
    federal => 'true',
    active  => 'true',
 },

Would I just use a placeholder (?) in my statement and pass it in via
that?  It will be in a loop as I have quite a few.

Use a hash slice to extract the values in order:

   # @fields is the collection of keys from your
   # data that match the order of your query.
   #
   # Nice thing about this trick is that you
   # can have more keys in the data than you
   # actually insert (e.g., the data may require
   # more than one query to insert).

   my @fieldz = qw( date type federal active );

   my $sth = $dbh->prepare
   (
       q{
           insert
               blah blah
           values
               ( ?, ?, ?, ? )
       }
   );

   ...

   # sometime later you set up a hash[ref] of
   # stuff to insert and just hash-slice it
   # to get what you need out:

   my $data =
   {
       date    => ... ,
       type    => ... ,
       federal => ... ,
       active  => ... ,
       foo     => ... , # these don't hurt anything
       bar     => ... , # since @fields doesn't include them.
   }

   $sth->execute( @[EMAIL PROTECTED] );


--
Steven Lembark                                       85-09 90th Street
Workhorse Computing                                Woodhaven, NY 11421
[EMAIL PROTECTED]                                     1 888 359 3508

Reply via email to