SPUG: Not again...
Steve Laybourn
otter101 at hotmail.com
Tue Jan 4 14:38:37 CST 2000
Wow!
OK, I can see that I am screwing up Perl in a major way.
I suppose I should not have said that in the case of:
my ($ix)=shift;
that @_[0] was equivalent to $_ (even though it did in an extremely
limited sense for that statement only). I have been informed of my error.
I have one more question that will doubtless irritate people even more...
Search engines...
Now, there are a couple of ways I have done this, none of them
particularly good...
One way was to use:
$hit=index($wossname[$x],0,$searchstring);
for each element in the array. If a -1 was returned, no match. OK. It
seemed like a rather inefficient way to do a search engine, but it works
pretty darn good for locating what line in an HTML/Perl/C++ script (or
scripts) something occurs.
Another way was to use a regex:
if ($wossname[$x]=~ m/$searchstring/i) { &GizzaHit; } else { &NoHitz; }
which seems to work quicker, but multiple words yielded too many multiple
matching result strings, requiring another routine to filter out duplicates
from the found list...
The other way I recently learned was:
@hitz=grep(/$searchstring/, at array);
which seems to almost work the quickest, except the duplicate matches
really pile up quickly in this one...
I know I sound like a total dweeb for asking this, but what is really the
best and most efficient way to search an array (record-by-record, \n is the
record separator) for a particular substring? And if there is no way to
avoid temporary duplicate matches, what is the best way to clean them up
other than a sort-and-pack loop?
I'll just bet someone will be waiting for me outside the next SPUG
meeting with a tar melter and a couple of dozen goose-down pillows...
Oh well.
Thanks again, everyone,
Steve Laybourn
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list