I think that I found the answer to my first question. I think that this would work: my $authorid = $dbh->selectrow_array("SELECT authorid FROM author WHERE name = ?", undef, ($_))
However, if I use that, or define %db_attrs as Philip suggested at the beginning of my program and use: my $authorid = $dbh->selectrow_array("SELECT authorid FROM author WHERE name = ?", \%db_attrs, ($_)) I get this error: [EMAIL PROTECTED]:~/popline$ ./pop2sql.pl w Bedford JM Use of uninitialized value in concatenation (.) or string at ./pop2sql.pl line 102, <> line 2. Can't execute statement: at ./pop2sql.pl line 102, <> line 2. [EMAIL PROTECTED]:~/popline$ This is confusing to me because I print $_ just before; it's value is "Bedford JM" printing just before the error above. It's late and my brain is fried. Can anyone see the error I'm obviously overlooking? Thanks. -Kevin >>> KEVIN ZEMBOWER <[EMAIL PROTECTED]> 05/05/05 03:51PM >>> Philip, thank you very much. I overlooked the meaning of the second variable to selectrow_array entirely. Two follow up questions: 1. If I don't need or want DBI handle attributes (I'm happy with the defaults, for instance), how can I define a null hash reference? 2. I chose selectrow_array specifically because I didn't need the prepare/execute/fetch routine. The query result is either a) the author is already in the table, and I want the record id number, or b) the author isn't in the table, and I'm going to add the name and then find the record id number of the record just added. There should never be more than one matching author name in the table, so I didn't think I needed a fetch capable of multiple rows. You're suggesting I look at fetchrow_array(). Am I overlooking something that you're aware of? Thanks, again, for your help. -Kevin >>> "Philip M. Gollucci" <[EMAIL PROTECTED]> 05/05/05 03:38PM >>> KEVIN ZEMBOWER wrote: >I'm using a function from DBI that needs a hash reference according to the >documentation, and I don't know how to turn $_ into one. The section of code I >have is: > if ($record{"Author"}) { > my @indfields = split(/\|/, $record{"Author"}); > foreach (@indfields) { > my $authorid = $dbh->selectrow_array("SELECT authorid FROM author > WHERE name = ?", $_) > or die "Can't execute statement: $DBI::errstr"; > > > > perldoc DBI The second argument to this is a hashref of DBI handle attributes not the bind values you want: $dbh->selectrow_array($sql, \%db_attrs, ($_)); somewhere above: our %db_attrs = ( RaiseError => 1, PrintError => 0, AutoCommit => 1, Taint => 1 ...... ); Also, the how point of using bind values is you should $dbh->prepare() your query outside of the loop. then $sth->execute($_) in the loop. and $sth->finish() after the loop. Check out $sth->fetchrow_arrary() instead. HTH -- END ----------------------------------------------------------------------------- Philip M. Gollucci Senior Developer - Liquidity Services Inc. Phone: 202.558.6268 (Direct) E-Mail: [EMAIL PROTECTED] Web: http://www.liquidation.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>