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?
Dec 4, 1999, 11:05 AM
Veteran (2260 posts)
Dec 4, 1999, 11:05 AM
Post #2 of 6
Views: 3830
you want to match the EXACT URL?
you can put
@results = grep {/^$in{'url'}$/} @db;
which isn't really good.. but yea..
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
you can put
@results = grep {/^$in{'url'}$/} @db;
which isn't really good.. but yea..
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
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).]
$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).]
Dec 5, 1999, 11:13 AM
Veteran (2260 posts)
Dec 5, 1999, 11:13 AM
Post #5 of 6
Views: 3822
keep in mind that this is asking for a database that only has the URL for each line..
no other information..
does exactly what sumengen's does..
if this is for links.. the easiest way is to query url.db.. with
my @db = <DB>;
close DB;
my @results = grep {/^\d+\|$in{'url'}$/i} @db;
jerry
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
My point is, using regex for this job is unnesarily expensive.
------------------
Turk Scripts
http://turkiyem.com/turkscripts
------------------
Turk Scripts
http://turkiyem.com/turkscripts