On Thu, 17 Mar 2005, Ramprasad A Padmanabhan wrote:

> > Okay, so we're back to my other suggestion -- "require" it:
> > 
> >     {
> >         $script = get_name_of_script(); # names matter! pick good ones!
> >         $output = require $script or
> >             die "Couldn't 'require' $script\n$!\n";
> >         do_something($output);
> >     }
> > 
> 
> No I cant use require. Let me tell you why.

...maybe that would have been helpful at the outset :-)

> for eg 
> 
> { 
>    $recipient = "[EMAIL PROTECTED]";  # This will come from the MTA 
>    $scriptname = get_scriptname($recipient);
>
>    # if I do require here 
>     require "$scriptname";
> 
>     # HERE LIES THE PROBLEM 
>     somefunc($arg1,$arg2,$arg3)    # somefunc is defined in $scriptname
> } 

Okay, so now we're back to my other original suggestion -- use a module:

    { 
        $recipient  = "[EMAIL PROTECTED]";  # This will come from the MTA 
        $scriptname = get_scriptname($recipient);

        use $scriptname qw( somefunc );
 
        somefunc($arg1,$arg2,$arg3) # somefunc is defined in $scriptname
    } 

And now you just have to see that $scriptname exports somefunc().

If this gets called a lot, you may need to wrap it in an eval() so that 
the namespace doesn't get clobbered. (I think, I'm a little confused as 
to what would happen in that case, but it seems like an eval should 
smooth out many glitches...).

> Also I cannot go on requiring files again and again, my process will 
> hog all the memory then.

Well, yes, but the way you've designed this, you already run that risk.

Now if you replaced get_scriptname() with get_subroutine(), and found a 
way to abstract out the bits that are different for each $recipient, 
then you could simplify things tremendously, and hopefully make your 
resource needs go way down:

    {
        $recipient = "[EMAIL PROTECTED]";  # This will come from the MTA
        $sub_name  = get_subroutine($recipient); # do this in one step

        $sub_name->($arg1,$arg2,$arg3);
    }

This will do everything without making any external calls.



-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to