in reply to Placement of Subs

Mostly, it's a problem of style. If you know what you are doing, it doesn't really matter. There are some pitfalls that you should be aware of, though.
Consider the following case, with subs on bottom, and calls to the subs on top. You see that there is a variable $stuff, declared before the sub. So you think it shouldn't be a problem to call your sub, which should print "ABCD". Unfortunately, it doesn't work like that. Your variable doesn't get initialized, because the program flow hasn't reached that point yet.
#!/usr/bin/perl -w use strict; dosomething(); my $stuff = "ABCD"; # bottom sub sub dosomething { print "$stuff\n"; }
OTOH, if you put your call to the sub at the end of the file, transforming your sub into a "top" sub, then you face the problem of unintended globals that Juerd is referring to. In the following case, your "dosomething" will work as expected, unless you call "dosomethingelse" first, in which case your lexical variable gets changed.
Using globals (including unintended ones) in this way is not recommended. If you really must have them, consider either creating a package or using closures.
#!/usr/bin/perl -w use strict; my $stuff = "ABCD"; # visible to all subs from now on #top subs { # start closure my $privatestuff = "WOW!"; #visible only from dosomething sub dosomething { print "$stuff \t $privatestuff\n"; } } # end closure sub dosomethingelse { $stuff = "WXYZ"; } dosomething();
Most of the problems that you might have with subs are related to using globals (or lexically scoped that act like globals) or not.
If your subs use parameters instead of globals, there are no such side effects when you call them, no matter where they are declared. The only difference will be that you have to use parentheses when you call subs that have not been defined yet.
#!/usr/bin/perl -w use strict; dosomething("ABCD"); #top subs sub dosomething { my $arg = shift; print "$arg\n"; } dosomething "EFGH";
My personal recommendation is: if you have a lot of subs, consider making a module out of them.
HTH
 _  _ _  _  
(_|| | |(_|><
 _|