welle has asked for the wisdom of the Perl Monks concerning the following question:
Hello
I am trying to extract from a column of a SQLITE-DB (containing text sentences) sentences that contain a string ($query). I normally use:
$results = $dbh->selectall_arrayref("SELECT ID, sentence FROM texts +WHERE sentence LIKE '%$query%'"
which is working pretty good (every sentence containing $query somewhere is extracted). What I'd like to implement is a matching only for entire words. I thought the following would do the game (note the white spaces between and after $query):
$results = $dbh->selectall_arrayref("SELECT ID, sentence FROM texts +WHERE sentence LIKE ' %$query% '" <\code> <p> Of course it doesn't work as I expected: <code> $query="tag" sentence1= "Put tags around your paragraphs" sentence2= "Put a tag around your paragraphs" sentence3= "I am tagging your paragraphs" sentence4= "There are many advantages"
I get rid only of sentence4 (no white spaces left and right of "tag"
What I am doing wrong?"
Back to
Seekers of Perl Wisdom