Declare variables as late as possible (if you want the advantages of use strict;). -- Huh? While declaring variables in an as restrictive scope as necessary is usually a good thing, what does that have to do with any advantage of use strict?
The first use of a variable is usually important for consequent uses. If you declare the variable as late as possible, you make sure the program breaks when you remove the first use, but not all others.
Now, I remove the assignment:my $foo; # Predeclared: bad style # Usually done by C-coders, who predeclare a whole bunch of variables: # my ($foo, $bar, $baz, $quux, $whatever, $i, $think, $is, $needed, $a +nywhere); ... $foo = foo(); ... print $foo;
However, if you declare $foo as late as possible:my $foo; ... print $foo; # No error, just a warning at run time.
Removing the assignment again:my $foo = foo(); # Declared when needed ... print $foo;
... print $foo; # Error at compile time!
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
In reply to Re: Re: Code Efficiency
by Juerd
in thread Code Efficiency
by fourmi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |