#!env perl # # ex_sql_placeholders_via_tied_variables.pl # use strict; use warnings; use PH: # my fake placeholders package # Tell PH which variables are to be converted into placeholders. tie my $c1, 'PH'; tie my $c2, 'PH'; tie my $c3, 'PH'; tie my $c4, 'PH'; my $table='a_table'; sub the_sql { "select foo from $table where x=$c2 or y in ($c3, $c4, $c1)" }; # Prepare the statement my $X = PH::prep(\&the_sql); # Set up some values and execute: ($c2, $c3, $c4, $c1) = ('b','3','e','f'); PH::exec($X); # Again... ($c1, $c2, $c3, $c4) = ('m','n','o','p','q'); PH::exec($X);