[EMAIL PROTECTED] wrote: > ------------------------------------------------ > On Thu, 20 Mar 2003 14:06:56 -0000, "Rob Dixon" > <[EMAIL PROTECTED]> wrote: > > > > > Wiggins' post got me to think a little more carefully, and it is > > clear > > that Train.pm is doing the redefining at its line 106, not > > ScheduleDay. > > That means that the definition must already exist when the 'use > > Train' > > statement in ScheduleDay is executed, as none of the Train code > > is executed anywhere else. Since 'use' is an implied BEGIN block I > > can't see any way this is possible. > > > > Can you put me out of my misery Rob, and tell us what's on Train.pm > > line 106? > > > > I was hoping someone would correct me, if you have? ;-)
No I wasn't. It's just that your post made me go back and think harder. I had written than it was ScheduleDay::new that was being redefined, but now I'm pretty sure it will be Train::new, as the code at Train.pm line 106 was trying to redefine a 'new' that had already been defined. At this point in the compilation the ScheduleDay module has done nothing but 'use Train' so I don't think there can be anything in its symbol table yet. > After reading Bob's e-mail I paid closer attention to the error > and thought in terms of compile time rather than runtime... > But I am a bit confused about the order of compiling, does the > whole file get compiled, then the module, and then they get > "linked" or is it sequential so that as soon as a non-previously > compiled 'use' is reached, then the that is compiled and then > returns to the original point to finish that file? This latter > seems to make more sense, but then that doesn't mean it is > the case. I really ought to read up more on Perl Neither really. The whole process is an orgy of compilation and execution, with the compiler calling the interpreter to execute BEGIN blocks in the middle of the compilation phase, and the interpreter calling the compiler to process eval expressions and s///ee constructs. The compiler will process, in this instance, ScheduleDay.pm until it comes to 'use Train'. This is a hidden BEGIN block so as soon as it is compiled it will be executed before the compiler continues through the file. Execution calls 'require' (which compiles the Train.pm file) and then the 'import' function of the Train module which is almost always either non-existent (if it is an OO module) or inherited from Exporter::import. Once this is done the compiler continues where it left of in the ScheduleDay.pm file - immediately after the 'use' statement. > I really ought to read up more on Perl internals, but finding > the time when I want to make my head hurt is difficult at > best ;-)...... The difficulty is that Perl doesn't follow the pattern of traditional languages, which are compiled to an link form, linked to an image and then run. The Perl compiler and interpreter are part of the same unit, allowing compile-time execution and run-time compilation. At least it avoids the need for dynamic linking! Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]