Lately I have taken on the maintainance of a legacy Perl 5 script. The script heavily uses the DBI function bind_columns() for retrieving data from a relational database. After some refaktoring I ended up with something like this:
my $sth = $dbh->prepare(<<'END_SQL'); SELECT color, food, num_legs FROM pet END_SQL my ( $food, $something_else, $color, $num_legs); $sth->bind_columns( \$color, \$food, $num_legs );
my $sth = $dbh->prepare(<<'END_SQL'); SELECT color, food, num_legs FROM pet END_SQL $sth->bind_columns( \( my ( $color, $food, $num_legs) ) ): my ( $something_else );
my @names = @{$sth->{NAME_lc}}; # or _uc
my %hash; $sth->bind_columns(\@hash{@names});
Also, in your code, you don't need the parens around "my(...)", though if you like them you can keep them