Richard C 1 wrote:
> I think I'm right, but I want to verify it. I'm learning PERL on my own
> and "decomposing" some programs to see how they "flow". My question is -
> given the following program "structure", what will print out?
>
> Print "one"
> Subroutine aa
>   print "two"
> End
> Print "three"
> Print "four"
> Subroutine bb
>    print "five"
> End
> Print "six"
> Sub "aa"
> Sub "bb"
> Print "seven"
>
> Given that this "pseudocode" executes, am I correct in saying that the
> following will print out (if it were really coded and run...):
>
> One
> Three
> Four
> Six
> Two
> Give
> Seven
>
> If this is not the order that things would "print out", what IS the
> correct sequence?

You're exactly right, but remember that you wouldn't actually do
that as it's not immediately obvious what it would do! In general
all the top-level code, which actually does something, will go first
while all the subroutines, which only do something if they're called,
will go last. Also you'd tend to name the subroutines after what they
did, like this:

    Print "one"
    Print "three"
    Print "four"
    Print "six"
    Sub "print_two"
    Sub "print_five"
    Print "seven"

    Subroutine print_two
        print "two"
    End

    Subroutine print_five
        print "five"
    End

and then the source of your program pretty much answers your
question itself!

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to