Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Re: Re: Re: Perl and MySQL - performing a search...

by Trimbach (Curate)
on Jan 27, 2003 at 22:20 UTC ( #230372=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Perl and MySQL - performing a search...
in thread Perl and MySQL - performing a search...

Sure, that'll work... you can get your long list of bad words from anywhere: a database table, an external file, a __DATA__ section, whatever.

A couple of small comments: you should avoid using "*" when you SELECT in your code. If you really want all the columns it's much better to select them by name. Not only do you conserve memory and bandwidth by selecting only what you need, but your code is better documented and you get to avoid future problems if you ever decide you want to fetchrow() instead of fetchrow_hashref().

Secondly, I'd re-arrange your code a little:

$sth = $dbh->prepare (qq{ SELECT f_user FROM `forbidden_usernames` }); $sth->execute(); while($row = $sth->fetchrow_hashref()) { if ($row->{f_user} =~ m/$str/i || $str =~ /$row->{f_user}/i) { return ("bad"); } }
The $sth->finish isn't really necessary unless you have a LOT of data in your result set...but that's just a matter of style. TMWOWTDI.

Gary Blackburn
Trained Killer

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://230372]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2020-08-09 11:59 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (54 votes). Check out past polls.