Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How to efficiently return the set of REGEX expressions matching 1 line of input?

( #38139=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on Oct 24, 2000 at 20:18 UTC
Q&A  > regular expressions


Description:

If you have potentially 100's of regex expressions in a hash table (the keys, the values are other info), how would you efficiently return these keys as a set, such that you could itterate over them, using the values to do other things?

Answer: How to efficiently return the set of REGEX expressions matching 1 line of input?
contributed by Ovid

Actually, davorg didn't miss the point. What he did was answer your question. If the specs are not clear, the answers won't be, either.

To get a better answer to your question, post to Seekers of Perl Wisdom. Include some sample code, sample lines from the file, and some of the regexes.

If your concern is speed, you'll need to learn about regex optimization. If you are iterating over lines in a file and iterating over hundreds of regexes, you may wish to reconsider how you are processing your data if speed is a consideration. Heck, if your data isn't clean and you have just one bad regex, your program may never finish running. For an example of some of the problems involved with regex optimization, read Death to Dot Star!.

Restating your problem and asking for optimization advice may help.

Answer: How to efficiently return the set of REGEX expressions matching 1 line of input?
contributed by davorg

Er... the keys function, I expect.

Answer: How to efficiently return the set of REGEX expressions matching 1 line of input?
contributed by Anonymous Monk

You missed the point. What is the fastest way to test 100's of regex expressions against every line in a file? Here is what I've come up with:

# map REGEXs over line 72.328 user, 0.108 sys, 1:24.18 real, 86.0% cpu 0k text, 0k data+stack, 0k avg, 0k max 36 in, 3 out, 0 faults, 325 reclaims, 0 swaps # eval preformed REGEXs over line 196.128 user, 0.093 sys, 3:47.98 real, 86.0% cpu 0k text, 0k data+stack, 0k avg, 0k max 43 in, 3 out, 0 faults, 358 reclaims, 0 swaps # eval over preconstructed function 1.742 user, 0.030 sys, 0:02.00 real, 88.5% cpu 0k text, 0k data+stack, 0k avg, 0k max 19 in, 1 out, 0 faults, 329 reclaims, 0 swaps

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (11)
    As of 2014-10-31 09:16 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (215 votes), past polls