On Mon, Jun 23, 2003 at 10:04:22PM +0200 Hamish Whittal wrote: > I have this scenario: > I have a 'main' program that needs to call on progA under condtions A, > progB under conditions B, etc. > > Now, I would like the progA, progB, progC to remain independent of the > 'main' program at all times. The only thing I would like to connect them > is the paramteres.... > Yes, I know this sounds like the place to use Modules and Packages, > however, I don't think a module can have a 'main' program of it's own. > The reasons for keeping this independence is to keep the whole system > portable and modular. At runtime, the users may choose to leave out > progC and hence the program will not even load this 'program' or set of > programs.... > > Can this be done? > > I am not sure I am explaining this correctly, so if not, I will try > again.
I think you will have to explain a little more. Why is it important that each of your parts needs to have a 'main' program? From your description it still sounds as though a module would be a good idea. Take these two modules: # modA.pm package modA; use strict; use base qw(Exporter); @modA::EXPORT = qw(main); sub main { my $parms = @_; ... } 1; # modB.pm package modB; use strict; use base qw(Exporter); @modA::EXPORT = qw(main); sub main { my $parm = @_; ... } 1; And in your main program you use require() to pull in either of the two: # main.pl ... if ($conditionA) { require modA; modA->import; main("foo"); } if ($conditionB) { require modB; modB->import; main("bar"); } Using require() instead of use() has two implications: The first being that it happens at run-time. Had you used use(), both modules would have been loaded. In the above case this would have been a problem because both modules have and export a main() function. Secondly, require() wont automatically trigger the exporting of symbols from a module so you have to do that manually. This is done with PACKAGE->import. The import() method is inherited by your modules from the Exporter module. It exports everything that is in @PACKAGE::EXPORT to the caller (which is main.pl in this case). Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]