On Jun 13, 2013, at 11:33 AM, lee wrote: > Shlomi Fish <shlo...@shlomifish.org> writes: > > >>>>> our $fh; >>>> >>>> Why the our? >>> >>> I've been reading that you need to declare variables before using them >>> when you use strict. A "my $fh;" would probably suffice. >> >> You can do the declaration during the open. > > Yes --- but I like it when the variables are declared in a "consistent" > way like you do in C, rather than declaring them all over the place > and/or even within other statements. I haven't figured out yet how I'll > do this in perl.
You should declare variables as late as possible. That is true in both C and Perl. Old C compilers would force you to declare variables at the beginning of each subroutine, but that is no longer the case. Putting all of the variable declarations at the beginning of the subroutine expands their scope and lifetime unnecessarily, which can lead to variable interference problems and turns local variables into global ones. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/