On Sat Jan 03 2009 @ 11:00, John W. Krahn wrote: >>> David Newman wrote: >> I always found it "cleaner", and have heard others say it's preferable, >> to declare all variables at the top of the program (although admittedly >> I didn't do that even in this short script). > > It is always better to limit the scope of variables. If variables need > to be in file scope anyway then a few lines one way or the other > probably won't make that much difference.
So, I'm curious about this now. I've also read the advice always to declare all variables at the top of the program (in C books, perhaps, or shell script books and tutorials?). But Perl-centered advice always seems to be the other way around: limit the scope of variables; declare things only when you need them (and in the smallest scope possible). The second approach makes sense to me, and I use it, but I'm wondering what motivated the original approach. Was it simply a wrong-headed attempt to be "logical" - all the variables go here, then main, then the functions, etc.? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/