[EMAIL PROTECTED] wrote: > I'm new to PERL and am trying to learn by reading some PERL programs. > > My question is this - does PERL execute sequentially and "skip around" > embedded subroutines or > Does it execute them inline? > > For example, if the program has the following set of code lines
It is helpful to stop here and recheck your concept of code structure. Lines are meaningful only as debugging indexes in Perl. *There are not units of code*. Commands are delimited by semi-colons, and blocks by braces. > > Line1 > Line2 > Line3 > Sub1 > Subcode1 > Subcode2 > Endsub1 > Line4 > Line5 > Line6 calls sub1 > Line7 > > Does the execution sequence go like this: > > Line1, line2, line3 line 4 line5, line6, sub1, subcode1, subcode2, > endsub1 line7 > > Or does it go like this: > > Line1, Line2, Line3, Sub1, Subcode1, Subcode2, Endsub1, Line4, Line5, > Line6, Sub1, Subcode1, Subcode2, Endsub1, Line7 > Generally, I would expect it to go kablooie. The intersperding of random lines of global script among subroutine definitions indicates poor program design. Although I often will write long sequences in global namespace when working out a problem, just to stay focused on the overall problem, I would not want to leave working code in that condition Generally, I seek to have the entire scripting content of a program covered in the first ten or twenty lines, and have everything beyond that properly encapsulaed in subroutine definitions. You gain much more control of progam execution by doing this, and can prevent and detect bugs much more easily. The overall structure of a program should be much more like #!shebang/path use strict; use warnings; use Other; whole_process(@ARGV); script lines sub whole_process { first_major_subprocess(); next_major_subprocess(); ... } sub first_major_subprocess{ useful_helper_process(); another_utility_process(); } sub useful_helper_process { } .. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>