string - Searching with Hash in Perl -


I am using a hash containing 5000 items to match the words in a sentence, this happens when I match for example: if ($ hash {$ word}) {something} Sometimes it happens that the term is in the word and even if it is a match that is a non- -Match is the presence of periodic results. Can anything be done to ignore any punctuation when matching a hash?

You must redefine the words you are looking at to leave the punctuation Remember that you probably do not want to eliminate all the punctuation marks (for example, you want to keep dash and apostrophs - but not a single quote).

Crude techniques - Do not recognize any punctuation marks:

  $ key = $ word; $ Key ~ = s / w / g; # Any non-word characters are removed (defined $ hash {$ key}) {DoSomething; }   

You can refine the options command to meet your needs.

But the only way to ensure that matches the hash key is to ensure that hashed key matches - so you should be consistent with whatever supplies you have.

Comments