Ask a Question related to PERL Beginners, Design and Development.
-
Richard C 1 #1
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
-
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... -
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... -
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... -
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... -
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, -
Jeff 'Japhy' Pinyan #2
Re: In what order does a program run..??
On Feb 4, [email]Richard.C.1@bwc.state.oh.us[/email] said:
Perl *compiles* subroutines when it sees them, but does NOT run them>My question is this - does PERL execute sequentially and "skip around"
>embedded subroutines or Does it execute them inline?
UNLESS you call them.
>Line1
>Line2
>Line3
>Sub1
>Subcode1
>Subcode2
>Endsub1
>Line4
>Line5
>Line6 calls sub1
>Line7Yes.>Does the execution sequence go like this:
>
>Line1, line2, line3 line 4 line5, line6, sub1, subcode1, subcode2,
>endsub1 line7
--
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
-
Wiggins D Anconia #3
Re: In what order does a program run..??
>
Perl or perl, never PERL. perldoc -q '"Perl"'>
> I'm new to PERL and am trying to learn by reading some PERL programs.
>
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]
It skips them as they are definitions....> My question is this - does PERL execute sequentially and "skip around"
> embedded subroutines or
> Does it execute them inline?
Correct (if I am understanding your 'sub1' correctly).>
> 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
>
You may want to look at,> Or does it go like this:
>
> Line1, Line2, Line3, Sub1, Subcode1, Subcode2, Endsub1, Line4, Line5,
> Line6, Sub1, Subcode1, Subcode2, Endsub1, Line7
>
> Thanks.
>
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
-
James Edward Gray II #4
Re: In what order does a program run..??
On Feb 4, 2004, at 9:52 AM, <Richard.C.1@bwc.state.oh.us> wrote:
Welcome then. Look's like you already got your answer, but here's a> I'm new to PERL and am trying to learn by reading some PERL programs.
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
-
Rob Dixon #5
Re: In what order does a program run..??
Wiggins D Anconia wrote:
Only on Unix:>> >
> >
> > I'm new to PERL and am trying to learn by reading some PERL programs.
> >
> Perl or perl, never PERL. perldoc -q '"Perl"'
perldoc "What's the difference"
will work.
Rob
Rob Dixon Guest
-
James Edward Gray II #6
Re: In what order does a program run..??
On Feb 4, 2004, at 12:11 PM, Rob Dixon wrote:
I believe you missed a -q in there:> 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"
perldoc -q "What's the difference"
James
James Edward Gray II Guest
-
Randy W. Sims #7
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:
In depth answer:> 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?
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
-
R. Joseph Newton #8
Re: In what order does a program run..??
[email]Richard.C.1@bwc.state.oh.us[/email] wrote:
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.> 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
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>
> 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
>
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



Reply With Quote

