In what order does a program run..??

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default In what order does a program run..??


    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

    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

    Thanks.

    Portions of this message may be confidential under an exemption to Ohio'spublic records law or under a legal privilege. If you have received thismessage in error or due to an unauthorized transmission or interception,please delete all copies from your system without disclosing, copying, or transmitting this message.

    Richard C 1 Guest

  2. Similar Questions and Discussions

    1. Tab Order always greyed out, need to redefine order but can't
      I had a check box but then i had to delete it and change it to a text field. now my tab order is all out of whack and I can't seem to set the tab...
    2. PDF and program won't open; "Error in Acrord32" "This program has performed an illegal operation and
      I recently had a browser hijacker. Fixed it with Norton and Lavasoft. Now, after downloading new Reader 6.0, I can't open anything. Only gives...
    3. Updating records in order (into an order)
      I'm storing questions for a user-defined quiz. I can store them in the order they are entered without any problem. But... The user needs to have...
    4. How to program order entry with input dependent filters
      Hi folks. Thanks in advance for you help. We're in the midst of a wholesale revision of our Access database to SQL so that orders can be directly...
    5. SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items mustappear in the select list if SELECT DISTINCT is specified.
      Dan, You should be able to do this: SELECT Id, FaxID, ReceivedTime, Pages FROM ( SELECT DISTINCT .Id AS Id,
  3. #2

    Default Re: In what order does a program run..??

    On Feb 4, [email]Richard.C.1@bwc.state.oh.us[/email] said:
    >My question is this - does PERL execute sequentially and "skip around"
    >embedded subroutines or Does it execute them inline?
    Perl *compiles* subroutines when it sees them, but does NOT run them
    UNLESS you call them.
    >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
    Yes.

    --
    Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
    RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    [ I'm looking for programming work. If you like my work, let me know. ]

    Jeff 'Japhy' Pinyan Guest

  4. #3

    Default Re: In what order does a program run..??

    >
    >
    > I'm new to PERL and am trying to learn by reading some PERL programs.
    >
    Perl or perl, never PERL. perldoc -q '"Perl"'

    Sometimes that is good, sometimes bad depending on who wrote the Perl
    you are reading, it is one way to pick up very bad habits. Does the
    code you are reading have:

    use strict;
    use warnings;

    At the top? If not you may be better off walking away slowly and then
    checking out a book (see suggestion below) or one of the free online
    resources first, then come back to the code. [url]http://learn.perl.org[/url]
    > My question is this - does PERL execute sequentially and "skip around"
    > embedded subroutines or
    > Does it execute them inline?
    It skips them as they are definitions....
    >
    > For example, if the program has the following set of code lines
    >
    > 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
    >
    Correct (if I am understanding your 'sub1' correctly).
    > Or does it go like this:
    >
    > Line1, Line2, Line3, Sub1, Subcode1, Subcode2, Endsub1, Line4, Line5,
    > Line6, Sub1, Subcode1, Subcode2, Endsub1, Line7
    >
    > Thanks.
    >
    You may want to look at,

    perldoc perl

    and review some of the basics. An excellent resource is also Learning
    Perl from O'Reilly and will get you all of the basics you will need and
    give you familarity with how to do things in a Perlish way.

    Good luck and welcome,

    [url]http://danconia.org[/url]
    Wiggins D Anconia Guest

  5. #4

    Default Re: In what order does a program run..??

    On Feb 4, 2004, at 9:52 AM, <Richard.C.1@bwc.state.oh.us> wrote:
    > I'm new to PERL and am trying to learn by reading some PERL programs.
    Welcome then. Look's like you already got your answer, but here's a
    tip: "perl" refers to the program that compiles and runs programs
    written in the "Perl" programming language, but we don't know what
    "PERL" is. ;)

    James

    James Edward Gray II Guest

  6. #5

    Default Re: In what order does a program run..??

    Wiggins D Anconia wrote:
    > >
    > >
    > > I'm new to PERL and am trying to learn by reading some PERL programs.
    > >
    >
    > Perl or perl, never PERL. perldoc -q '"Perl"'
    Only on Unix:

    perldoc "What's the difference"

    will work.

    Rob


    Rob Dixon Guest

  7. #6

    Default Re: In what order does a program run..??

    On Feb 4, 2004, at 12:11 PM, Rob Dixon wrote:
    > Wiggins D Anconia wrote:
    >>>
    >>>
    >>> I'm new to PERL and am trying to learn by reading some PERL programs.
    >>>
    >>
    >> Perl or perl, never PERL. perldoc -q '"Perl"'
    >
    > Only on Unix:
    >
    > perldoc "What's the difference"
    I believe you missed a -q in there:

    perldoc -q "What's the difference"

    James

    James Edward Gray II Guest

  8. #7

    Default Re: In what order does a program run..??

    On 2/4/2004 10:52 AM, [email]Richard.C.1@bwc.state.oh.us[/email] 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?
    In depth answer:

    perl reads in your source file and parses the code from top to bottom.
    If it sees a 'use <module>;' statement it stops parsing your file, reads
    and parses the used module, and then resumes parsing your source. If it
    encounters any 'BEGIN' subs (there can be more than one), it executes
    the code in that sub as soon as the complete sub has been completely
    parsed, but before parsing the remainder of your source. After the
    source has been parsed, perl executes any 'CHECK' subs (there can be
    more than one) beginning with the last, continuing in the *reverse*
    order of definition. If you specify the '-c' (compile-only) switch, the
    process ends here. Otherwise perl continues execution at the top first
    with the execution of any 'INIT' subs in the order they are defined.
    Then perl begins executing any code at file scope, executing code in
    subroutines only when (or if) they are called. Afterwards, perl executes
    any 'END' subs in reverse order of definition.

    Randy.


    Randy W. Sims Guest

  9. #8

    Default Re: In what order does a program run..??

    [email]Richard.C.1@bwc.state.oh.us[/email] 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

    R. Joseph Newton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139