Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
It drives me nuts when guys seperate their programs into
multiple subroutines for no good reason, and I get especially
excercised when you interleave the subroutine definitions
with the main code which calls them.
If you _really_ want to make me crazy, nest each function within the previous one to add needless complexity! I can't believe they taught you to do that in school. If these subroutines are doing significantly different or reusable things, maybe. Otherwise just make it all one long block. I'm NOT encouraging you to make all the variables global. you can certainly scope your variables within the blocks of code in which they're used. Heck, enclose the blocks in braces {} to limit the scope of a variable, but they DON'T have to be functions! Take this: func1(); func2(); func3(); 'twas indented, but the silly formatter mashed that.... sub func1 { my $variables; } sub func2 { my $more_variables; } sub func3 { my $other_variables; } and eliminate everything but the braces: { my $variables; # Code to use these variables } # End of scope of $variables { my $more_variables: # Code uses more_variables } # End of scope of $more_variables { my $other_variables # Use other_variables } # end of scope of $other_variables. I usually find myself making enough blocks in braces as a "natural consequence" of conditional statements and other flow control to not have to add additional braces to control the scope of my variables. In reply to Re: Style & subroutine organization
by Anonymous Monk
|
|