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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |