in reply to RE: I want to be a Perl Jedi
in thread I want to be a Perl Jedi

if you're going to start combining regular expressions, you may as well condense them further.

/\b12345\b/ and /\b12346\b/
can become
/\b1234[56]\b/

and
/\b31337\b/ and /\b31338\b/
can become
/\b3133[78]\b/

and
/\b54320\b/ and /\b54321\b/
become
/\b5432[01]\b/
hope this helps some more.

Update (to jcwren): good point. i totally agree. i didn't realize this was port numbers and that they might change in the future.

Replies are listed 'Best First'.
(jcwren) RE: I want to be a Perl Jedi
by jcwren (Prior) on Jul 18, 2000 at 18:01 UTC
    jlistf, I can't (and won't) disagree that the regexp optimizations you've offered do optimize the search. But this is really the kind of data that should not be optimized. Since ports can change, new scanners can come (and go), etc, optimizing the regexp seriously decreases the maintainability of the script. The next person that comes along may not be a Perl programmer.

    To this end, the script should contain an array at the top, with the list of port numbers, along with explicit instructions as to how to add/delete/change a port number. The next person shouldn't have to learn regexp just to update the ports to be checked for.

    So, you get a virtual ++ for reducing the regexp, but a virtual -- for making it more unmaintainable. (which really means I just don't vote on the node).

    --Chris

    e-mail jcwren