kiat has asked for the wisdom of the Perl Monks concerning the following question:
I'm quite used to declaring variables as follows:
That is, without initialising them with default values.my ($title, $page, $chapter);
I also find it quite common in other people's code that I've come across.
I'm wondering, after reading about variables being set to old values under mod_perl, if it might be better in general to initialise each and every variable. So, instead of the above, we now have:
It's more work definitely but it generally makes the code more readable (for instance, if I've no idea what 'page' means, I at least know the variable $page is going to be used for some numerical value). There're probably also some gains in performance as the interpreter doesn't have to make guesses about those values.my $title = ''; my $page = 0; my $chapter = 0;
Is it merely a preference thing? Or is one method better than the other?
I look forward to reading your views. Many thanks in advance :)
update: It's been very enlightening reading your comments on the node. It seems not initialising the variables is the normal thing to do in most circumstances. Thanks once again for your sharing :)