in reply to using strict and functions
In addition to the excellent technical answers you're getting, let me also add a style comment.
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: using strict and functions
by rob_au (Abbot) on Jan 18, 2002 at 04:27 UTC | |
Re: Re: using strict and functions
by metadoktor (Hermit) on Jan 18, 2002 at 00:58 UTC | |
by talexb (Chancellor) on Jan 18, 2002 at 07:14 UTC | |
by IlyaM (Parson) on Jan 18, 2002 at 08:36 UTC |
In Section
Seekers of Perl Wisdom