http://www.perlmonks.org?node_id=989136

In a former programming life in a different programming language, placeholders of the ":placeholder" type were bound by reference to variables in the program. With DBI, we generally use bind_param() to bind by value a copy of some variable. But bind_param_inout binds by reference, so I was thinking what if I go ahead and use that anyway, e.g.:
my @cols = qw(foo bar); my $sql = <<SQL; SELECT :foo, :bar FROM dual SQL my $sth = $dbh->prepare($sql); my %hsh; for (@cols) { $sth->bind_param_inout( ":$_" => \$hsh{$_}, 0 ); } # Set constants... $hsh{foo} = 'abc'; # Set changing values $hsh{bar} = 123; $sth->execute(); while (my @arr = $sth->fetchrow_array) { print "@arr\n"; } $hsh{bar} = 456; $sth->execute(); while (my @arr = $sth->fetchrow_array) { print "@arr\n"; } $dbh->disconnect();
And it worked (this was for Oracle, thus, the 'FROM dual'). This is, of course, just an example SQL statement, but may also be most useful for others, like INSERT statements...