I'm attempting to pre-build part of a SQL statement in perl before passing it to the DBI engine. My SQL statement needs to do a like in the DB engine, and I'd intend to utilize the SQL % sign. However, the presence of the % sign in the string has perl attempt to satisfy the %B or %1 as the string gets assigned instead of just passing it along as a string.
I'd like my SQL statement to eventually resemble the following:
select winner from results where round='2' and (event like '%USA%' and + event like '%Boys%');
here's a code snippet example of the perl I'm attempting to write:
if ($form{'category'} eq 'All USA Boys') { $clause="(event like '%USA%' and event like '%Boys%')"; } printf "Existing clause assignment logic; clause variable is $clause<p +>" if $debug;
The printf of the above code ends up as follows:
Existing clause assignment logic; clause variable is (event like '0SA%' and event like '0oys%')
%U got turned into 0, as did %B. This also happens with a few other words where I attempt to wrap the word in a like statement.
How do I get Perl to NOT interpret this and to pass the string along as intended?
I've tried escaping the % sign with a \, tried \Q and \E, tried replacing the % sign as a variable, tried breaking up the strings at the % signs and then re-concatenating them, etc. All to no avail.
Hoping i'm missing something simple...thanks in advance.
In reply to Escaping % sign in a like string bound for SQL by bfr7kq6
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |