Gossamer Forum
Home : General : Perl Programming :

Matching full terms with Grep

Quote Reply
Matching full terms with Grep
Does anyone know how to use grep to match a form input with database input? I have this but say the url is www.netscape.com, if i put in the form www.net it will still show how many times www.netscape.com is in. I would like it to match every letter in the form input. Anyone know how?
Quote Reply
Re: Matching full terms with Grep In reply to
you want to match the EXACT URL?

you can put

@results = grep {/^$in{'url'}$/} @db;

which isn't really good.. but yea.. Smile

you might also want to come up with a BIG REGEXP to match different types of the same url..

for example..

you can regexp a built regexp string (like search.cgi of links 2.0).. or you can do the same by doing this

@results = grep {/^$url$/ || /^$urlWoWWW$/} @db;

etc..

jerry
Quote Reply
Re: Matching full terms with Grep In reply to
All suggestions either make it say there are no instances of the url in the database, or that there are way more than there really is.
Quote Reply
Re: Matching full terms with Grep In reply to
How about:

$no_of_results = grep { lc($_) eq lc($in{'url'}) } @db;


------------------
Turk Scripts
turkiyem.com/turkscripts

[This message has been edited by sumengen (edited December 05, 1999).]
Quote Reply
Re: Matching full terms with Grep In reply to
keep in mind that this is asking for a database that only has the URL for each line..

no other information..

Code:
@results = grep {/^$in{'url'}$/i} @db;

does exactly what sumengen's does..

if this is for links.. the easiest way is to query url.db.. with

Code:
open DB, "url.db";
my @db = <DB>;
close DB;

my @results = grep {/^\d+\|$in{'url'}$/i} @db;

jerry
Quote Reply
Re: Matching full terms with Grep In reply to
My point is, using regex for this job is unnesarily expensive.

------------------
Turk Scripts
http://turkiyem.com/turkscripts