Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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?

Originally posted as a Categorized Question.

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

Replies are listed 'Best First'.
Re: How to efficiently return the set of REGEX expressions matching 1 line of input?
by Ovid (Cardinal) on Oct 24, 2000 at 22:01 UTC
    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.

Re: How to efficiently return the set of REGEX expressions matching 1 line of input?
by davorg (Chancellor) on Oct 24, 2000 at 20:21 UTC

    Er... the keys function, I expect.

Re: How to efficiently return the set of REGEX expressions matching 1 line of input?
by Anonymous Monk on Oct 24, 2000 at 21:47 UTC
    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