I can't speak authoritatively to any performance difference regarding initialization. However my engineering sense says that it is insignificant.

I can however speak from many years of experience writing code and maintaining code written by others. And I say this: If you start messing with the code to change things to "do it the way you would have done it", even if you make "obvious", "cannot be wrong" changes, you will probably screw it up, no matter how careful you are. Remember, you said it was a "huge script", and it presumably works now.

Then you'll be explaining to the boss why you are debugging code in areas you were not tasked to modify. And then you will ultimately toss your changes and go back and just make the required changes you were supposed to make.

I can also state without fear of contradiction that you will hardly ever pick up a piece of code and not see something you would do differently. Even if it is code you wrote yourself only a few months ago.

Now consider the example you provided, where you want to change $companyname = ""; to $companyname = undef;. Now you have broken all the code that uses length(), so you have to fix that. But even your proposed fix is broken if $companyname = "0";, so now you have to test for defined($companyname) && length($companyname) which is longer than the original. So your "simple, obvious" change caused problems which have to be tested for and debugged.

Bottom line: If it ain't broke, don't fix it. (Unless the current code doesn't use strict; then fix it.)


In reply to Re: How does variable definition affect Perl performance ? by gmargo
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.