Hi,
I need to solve a problem with perl.
I have lots of text file and have a wordlist with more than 100 words.
I will search every word in every text file, if a word matches (there is only one matched word in every text file) then I will record it to mysql db. So, I will search word1 in text1, then word2 in text1, then word3 in text1 (it matched and I recorded it). After that word1 in text2 word2 in text2 (it matched ...) and so on..
What is the best way to do so? My way is to assign all the words to an array, then search every word by for loop.
Is there any shorter/different way? For example, is it possible to search with one regex statement and get the matched word?
For instance, can I use or (|) character (like word1|word2|word3|word4) and get matched character? If it is possible, how can I get it?
Thanks in advance,
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.