Forum Moderators: coopster & phranque

Message Too Old, No Replies

Executing perl code from external file

         

Caley

1:51 am on Jul 11, 2005 (gmt 0)

10+ Year Member



ok, a simple newbie question for you fellas,

how do i execute code contained withing an external CGI file,

so far ive got,

open (CGIFILE, "<$cgifile") or die "cannot open file";
@code = <CGIFILE>;

but im confused to what i have to do with the @code array now

moltar

3:18 am on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, Caley!

eval [perl.com] join("\n", @code); 
die $@ if $@;

Hope this helps.

wruppert

3:28 am on Jul 11, 2005 (gmt 0)

10+ Year Member



I'm confused, I'm not sure why reading a file (presumably a perl script) into a second perl script has anything to do with running the first script.

Perhaps you could provide more details about the big picture... Are you operating at the command line or trying to get Apache to run the script? If the former, just type "perl scriptname", if the latter, something like "http://www.yourdomain.com/cgi-bin/scriptname". Assuming everything is setup OK.

If the first script is a module you want to use in the second script, you include it with "use modulename".

If you really do want to execute the first script from the second script, you might use exec, system, or fork. You can also use backticks, like a shell.

But none of these involve actually reading the file into an array. Of course, there is always "eval", I guess. As Moltar just pointed out I see...

Caley

10:18 am on Jul 11, 2005 (gmt 0)

10+ Year Member



cheers moltar, it worked a treat! thankyou