Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Short answer: no and no.

First question: initializing with $var = undef. Absolutely first: why aren't you using my? Secondly: 0, "" and undef are distinct values that can interact differently with the rest of the code, Don't assume that you can use them interchangeably.

Second question: length($string) == 0 vs if ($string): this is a good example of the difference mentioned above: 0, "0", undef and "" are all logically false in perl, but "0" and 0 are of length 1 while undef and "" are of length 0.

As for performance; this kind of nitpicking is unlikely to give you a speedup even a couple of orders of magnitudes smaller than the time you need to spend to make the change and test that the code will still work correctly, even if your code is running continously for a year or two. Look at the overall algorithm and its performance characteristics and improve that instead. For instance, minimize disk I/O in favor of using more memory if you can: for any file that's read more than once you're probably better off reading it into an array or hash table and keeping it there.

Even if you can't do that right now because of memory limits, it may be more efficient in terms of money and time to add a couple of Gb of RAM to the machine instead of messing about with the code. RAM is cheap and it'll only get cheaper, and so is CPU power; a couple of days worth of development time will buy you a top-of-the-line new machine. An hour or two development time will buy you a couple of Gb of RAM.


In reply to Re: How does variable definition affect Perl performance ? by Joost
in thread How does variable definition affect Perl performance ? by EdsterTech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-04-23 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found