in reply to Perl Warnings...
sub first_row { my ($dbh, $query, @args) = @_ my $sth = $dbh->prepare($query); my $rv = $sth->execute(@args); my $first_row = $sth->fetchrow_hashref; return ($rv, $first_row); } my ($success, $first_result) = first_row($dbh, "SELECT ... "); # and if you don't want to actually check success my $second_result = first_row(...);
(Update: or as ikegami points out, just use $dbh->fetchrow_hashref($query) in the first place.)
(Even more elegant if you don't check for $rv, but instead die on errors, and catch them where appropriate).
If you insist on your current pattern, you can use warnings, but disable single warnings that bother you - read perllexwarn for more details. Or simply put a block around the declarations.
|
|---|