Hi, you might like SQL::Abstract::More for building SQL statements that you can then execute with DBI.
Your particular query is simple, and since you obviously know that you do not have much data you are using selectall_arrayref, but things have a way of gaining complexity and/or volume with time. I always code for the future, which for me means eschewing hand-rolled SQL. YMMV.
use strict;
use warnings;
use feature 'say';
use SQL::Abstract::More;
my @tagList = ('red', 'black');
my $SQLA = SQL::Abstract::More->new;
my ($stmt, @bind) = $SQLA->select('tags', ['table'], {tag => {-in => \
+@tagList}});
say $stmt;
say "@bind";
# $dbh->selectall_arrayref($stmt, undef, @bind);
# ... etc.
__END__
Output:
$ perl 1230223.pl
SELECT table FROM tags WHERE ( tag IN ( ?, ? ) )
red black
Hope this helps!
The way forward always starts with a minimal test.
|