Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

RE: RE: Re: Search Algorithm

by tenfourty (Novice)
on Aug 10, 2000 at 19:49 UTC ( #27310=note: print w/replies, xml ) Need Help??

in reply to RE: Re: Search Algorithm
in thread Search Algorithm

Thanks to you all for your replies, this was the first time I had posted to this list and I'm amazed at the fast response.

I will typically be searching for around 200 keywords in up to 2000 files, I need to output in my log the name of the file, the number of occurences of keywords and then for each occurence of the keyword I need to print that line and the line number.

I think that you are right that a regexp is not the best way to search a line and that for each line I should check for the occurence of each word in a hash, my search should not be case sensitive as well, are the keys in a hash case sensitive, and if so how do I get around this?

Replies are listed 'Best First'.
RE: RE: RE: Re: Search Algorithm
by chromatic (Archbishop) on Aug 10, 2000 at 20:53 UTC
    Keys in a hash are case sensitive, but nothing says you have to store them in a particular case. Pseudo-workable snippet follows:
    foreach (@words) { $word_idx{lc($_)} = $position; }
    The important magic is in lc. You'll have to use lc when you pull values out of the hash, too, or use a tied hash that does this for you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://27310]
LanX .oO(positively thought)
[holli]: :) No. I might be small, but you don't want to be around me when I flip.
[LanX]: I can imagine ...
LanX hurts to be bitten between the legs ;-)
[holli]: You see, I have a friend whose daughter has been damaged seriously because she wasn't vaccinated against measles. (Her mother being anti-vaxx).
[LanX]: Contrary to Olivia newton John I don't like physical confrontations ...
[LanX]: Oh, you spread measles in your saliva?
[LanX]: ... and why did you bite hos daughter?
[LanX]: *his
[holli]: And this guy was also Anti-Vaxx and I just snapped. I shoed him all over the yard

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2017-12-13 18:01 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (373 votes). Check out past polls.