Only declare variables when you need them. If you need a loop variable, don't declare it away at the beginning of the routine or (horrors!) at the top of the file. Just declare it where you're gonna need it, like this:
If you're going to need two variables somewhere in the middle of a block of code, declare them there. In some languages you do have to declare all variables at the beginning (Pascal, and I think BASIC) .. but C and Perl give you more flexibility. So you could writefor ( my $Index = 0; $Index < 5; $Index++ ) { ... # code here that uses $Index }
This just declares the two variables where you need them. As soon as the scope (the code between the braces) ends, the variables disappear. Very neat, very clean.{ # Start black of code .. .. { # Start another block of code my ( $Index, $NodeNumber ); .. .. } .. .. }
--t. alex
"Of course, you realize that this means war." -- Bugs Bunny.
In reply to Re: using strict and functions
by talexb
in thread using strict and functions
by idunno
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |