Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Regex Optimization Question

by duff (Parson)
on Mar 23, 2006 at 18:54 UTC ( [id://538826]=note: print w/replies, xml ) Need Help??


in reply to Regex Optimization Question

I think I'd probably do it like this:

$string =~ /Win32_Account.Domain="(.*?)",Name="(.*?)"/; print $2 eq "" ? "Account Deleted" : "$1\\$2";
But I don't know if that's more efficient as you haven't told us what axis of efficiency you're interested in. There's efficiency in execution time, efficiency in memory usage, efficiency in programmer time, etc. Generally programmer time is the most important thing to optimize for, so if you understand my version and it does what you want, then maybe it's more efficient. :-)

Replies are listed 'Best First'.
Re^2: Regex Optimization Question
by ikegami (Patriarch) on Mar 23, 2006 at 20:05 UTC
    Using $1, $2, etc without knowing if the regexp matched is dangerous. For example,
    foreach ('foo', 'bar') { /(oo)/; print("$1\n"); }
    outputs
    oo oo
      True. I've found that in these cases, doing the regex with pattern memory in its own code block works.
      foreach ('foo', 'bar') { { /(oo)/; print("$1\n"); } }
        I didn't know that. Neat!
Re^2: Regex Optimization Question
by JavaFan (Canon) on May 16, 2011 at 09:37 UTC
    There's efficiency in execution time, efficiency in memory usage, efficiency in programmer time, etc. Generally programmer time is the most important thing to optimize for,
    IMO, it's actually very, very rare if there's a situation where you can pinpoint "the most important thing to optimize for".

    In fact, I cannot think of any.

    Generally, they are all important, and it takes a good programmer/manager/project leader to strike the right balance.

      Indeed. However, not having any information about where to focus on efficiencies, you can't go wrong on "programmer time" as a sane default thing to optimize. That's why it's generally the most important thing and not specifically the most important thing. :-)

        You got any data to back that up? Or is that just your opinion? Frankly, I doubt that it will still be your opinion if you gave it half a second of thought.

        Seriously, if programmer time would be "generally" the most important thing to optimize for, we shouldn't be writing documentation or tests, and copy-and-paste would be preferred over refactoring.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 13:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found