You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Wim Kerkhoff <wi...@merilus.com> on 2001/01/15 18:46:50 UTC

Using Execute with perl scripts

Hi Everyone,

I've been wanting to include the output of pure perl scripts in my
Embperl pages.

Is there a better way of writing the following line?

[+ `/var/www/intranet/parts/foo.pl`  +]

I want to make sure that I'm still taking advantage of mod_perl, and not
loading up the perl intepreter for each call of foo.pl.

-- 
Regards,

Wim Kerkhoff, Software Engineer
Merilus, Inc.
wim@merilus.com

Re: Using Execute with perl scripts

Posted by Gerald Richter <ri...@ecos.de>.
>
> Is there a better way of writing the following line?
>
> [+ `/var/www/intranet/parts/foo.pl`  +]
>
> I want to make sure that I'm still taking advantage of mod_perl, and not
> loading up the perl intepreter for each call of foo.pl.
>

[-
# instead of setting STDOUT to OUT (via select), you can also
# set optRedirectStdout, or print to OUT in your script
my $oldfh = select (OUT) ;
do '/var/www/intranet/parts/foo.pl' ;
select ($oldfh) ;
-]

this solution still compiles the script every time it is invoked, but
doesn't fork a new process to do so. To be faster you have to wrap the
content of your script in a subroutine, require the script and call the sub
afterwards. If you call this sub from within multipe pages, you should give
it an own namespace:

[-
# NOTE: require will _not_ reload your script when it changes,
#   you have to retstart the webserver for that!
require '/var/www/intranet/parts/foo.pl' ;
&foo::bar ;
-]

foo.pl looks like:

package foo ;

sub bar
     {
    print OUT "whatever" ;
    }

again you can redirect STDOUT to OUT as above.

Gerald




-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925151
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------