in reply to covert to string variable
Do something like this (always use placeholders when passing variables to your SQL DB):
use strict; use Data::Dumper; my (@array,@newarray); @array=("ABCDEF01","HIJKL678","VWXYZ123H"); # join 'USERNAME LIKE ?'x3 with ' OR ' my $str = join(' OR ', ('USERNAME LIKE ?')x@array); # prints USERNAME LIKE ? OR USERNAME LIKE ? OR USERNAME LIKE ? print $str; my $sth = $dbh->prepare("SELECT * FROM users WHERE $str"); # use map to convert each username in @array to 'match%' # passes (ABCD%, HIJK%, VWXY%) to execute $sth->execute( map { substr($_,0,4) . '%' } @array );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: covert to string variable
by Anonymous Monk on Oct 29, 2010 at 14:01 UTC |
In Section
Seekers of Perl Wisdom