Just another Perl shrine | |
PerlMonks |
Re: Basic programming questionby tall_man (Parson) |
on Jan 27, 2005 at 16:31 UTC ( [id://425606]=note: print w/replies, xml ) | Need Help?? |
There are several reasons to prefer B to A, IMHOP.
1) It is good practice to apply the principle of initializing variables to valid values as soon as they are declared. 2) The second way is more efficient. You avoid generating the code for entering an extra scope level (the else). 3) You may think the first way is avoiding an assignment to $T but that is not the case. Code is generated to assign an undef to it. (Update: I think I was mistaken about this one.. But the extra assignment cost is neglibible.) 4) It is just as readable, if not more so. You can view "AM" and an unmodified hour as the default, and "PM" with a subtracted hour as the exception. Try running both these codes with "perl -MO=Terse" and you will see the differences.
In Section
Seekers of Perl Wisdom
|
|