Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: covert to string variable

by james2vegas (Chaplain)
on Oct 28, 2010 at 16:17 UTC ( #868075=note: print w/replies, xml ) Need Help??

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
    Great. This is exactly what I wanted to do. Thanks for reminding me about the placeholders

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://868075]
[choroba]: very cloudy here, I planned to make some picrures, but now I don't think so
[LanX]: do you like it better now?
[choroba]: Well, getting used to it
[LanX]: several people told me they like saigon. ..
[choroba]: well, beer is good here, surprisingly
[choroba]: also, I discovered several vegan/vegetarian restaurants, so I can avoid meat
[LanX]: ha ha ... happy Czech :)
[choroba]: been to the War Remnants Museum, too. Quite a brutal experience
[choroba]: but still, small-talk about smuggling guns and how Trump is great with US expats isn't my cup of tea
[LanX]: brutal beer?

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-02-26 04:33 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (371 votes). Check out past polls.