I don't know if you realize that you just wrote an SQL statement. Have you
considered putting all of this in a DB? Use the DB to do the searching and
sorting, and Perl to display the results.

#!/usr/bin/perl -w

# quick DB sample, I know it doesn't use strict, sue me :-)

use DBI;

# connect
$dbh = DBI->connect("DBI:mysql:db_name:localhost","username",
"password") or die "Could not connect to DB: $!";

# search terms
$searchstring = "foo"; # you can get this from <STDIN>, param, etc.
$nosearch = "bar";     # we'll tell our SELECT this is not kosher

# build query
$statement = <<"END_OF_STATEMENT";
SELECT id,text FROM tableName WHERE text LIKE '%?%' AND NOT LIKE '%?%'
END_OF_STATEMENT

# execute and return results
$sth = $dbh->prepare(q{$statement}) or die $dbh->errstr;
$sth->execute($searchstring,$nosearch) or die $dbh->errstr;

while(($id,$text) = $sth->fetchrow_array) {
 print "$id - $text \n"; # prints rows containing "foo"
}                        # in the 'text' column

# finish and disconnect
$sth->finish;
$dbh->disconnect;




-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Friday, June 06, 2003 10:26 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: regexing AND NOT


Dear Ted,

thank you for answering so quickly.

The problem is, I don't want to make the users write
regular expressions. Of course, I have to test them with
the help of 'eval' in order to prevent that an illegal
regular expression is blocking the whole cgi-application.

The reason for not using regular expressions is that
my search application is meant for searching patterns in
a bilingual text (German and Russion), which is displayed
in cyrillic and with German umlauts. And it would be a lot
easier if I could just search for

   sun moon AND NOT suns moons

So, I appreciate all ideas.

Peter

-----------------------------------

Zitat von [EMAIL PROTECTED]:

> perlfaq6: (cut-n-paste to get the final "-" there)
>
http://www.perldoc.com/perl5.8.0/pod/perlfaq6.html#How-do-I-match-a-pattern-
that-is-supplied-by-the-user-
>
> How do I match a pattern that is supplied by the user?
> Well, if it's really a pattern, then just use
>
>     chomp($pattern = <STDIN>);
>     if ($line =~ /$pattern/) { }
>
> Alternatively, since you have no guarantee that your user entered a valid
> regular expression, trap the exception this way:
>
>     if (eval { $line =~ /$pattern/ }) { }
>
[...]
> Good luck,
> .ted

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to