John V. Pataki wrote:
> Hmm....
>
> I think most of it is working -- however ....
>
> Is there a way to have sub routines that are in my main program
> available to be called from code in the module?
>
> This is where I was thinking that blessing would make the code in the
> module act as if it were a part of my main program... but i am not to
> sure how to implement this.
>
> The code I want to pull out of my main and put into a module establishes
> a connection to another program -- I then send command from that app
> back to my perl program by calling subroutine names. However if the code
> for establishing the connection is now not apart of the main -- as in my
> module now -- the subroutine is not available to me now relative to the
> module? Or is it?
You could pass a coderef to the code in main for use by the
module.
Main:
some_sub_in_module (\&sub_in_main, $arg1);
...
sub sub_in_main { # main sub to be called by module
...
}
Module:
sub some_sub_in_module { # module gets coderef back to main sub
my ($coderef, $arg) = @_;
if ($arg > 3) {
&$coderef ($arg); # and calls it here
}
You can also call a sub in main by qualifying the sub with 'main::'.
I would discourage that though since it would require all scripts
that use your module to supply the same subroutine. There should
be no references back to main from the module if at all possible.
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs