Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^8: Speeding up named capture buffer access

by SBECK (Chaplain)
on Dec 01, 2009 at 20:18 UTC ( #810453=note: print w/replies, xml ) Need Help??

in reply to Re^7: Speeding up named capture buffer access
in thread Speeding up named capture buffer access

That's how I had it originally... and when you've got 23 different possibilities, it adds unnecessary complexity. There's already 23 possibilities wherever I create the regular expressions, but now there's 23 possibilities wherever I use it as well.

Worse is that some of the regular expressions are used multiple places. When I modify a regular expression, I'd like to have it be done in one place (wherever the regexp is created) and not have to worry about it in some other place or places (wherever it's used). As it stands now, I can add new ways to express a date in one place, and it'll automatically -- the routine where I create all my regexps, and it'll automatically go into affect in the various places it might be used.

Not a big problem of course... but I'm a huge fan of Larry's principle of laziness.

  • Comment on Re^8: Speeding up named capture buffer access

Replies are listed 'Best First'.
Re^9: Speeding up named capture buffer access
by BrowserUk (Pope) on Dec 01, 2009 at 20:42 UTC

    If you are willing to trade a few globals to obtain speed, then a dispatch table might allow for reasonable maintanence:

    my( $hrs, $mins, $secs, $day, $month, $year, ... ); my %res = ( qr[(\d\d):(\d\d):(\d\d)] => sub{($hrs,$mins,$secs) = ($1 +,$2,$3) }, qr[(\d\d)/(\d\d)/(\d\d(?:\d\d)*)] => sub{($day,$month,$year) = ($1 +,$2,$3) }, ..., '' => sub{ die "Unknown date format" }, }; ... $maybeTime =~ $_ and $res{ $_ }->() for keys %res;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://810453]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2021-06-25 07:39 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (134 votes). Check out past polls.