Forum Moderators: coopster & phranque

Message Too Old, No Replies

Dynamic content within static design in Perl

         

Jscally

7:36 pm on May 13, 2003 (gmt 0)

10+ Year Member



I have layed out a standard design template to use for most of the pages in my site. It consists of a table in which one of the cells will be filled with the output of a Perl script I have written.

What is the best way to do this?

I have read somewhere that I could use javascript to call the perl script. But I worry that the user will have Javascripts disabled.

Any thoughts would help me greatly.

BCMG_Scott

9:04 pm on May 13, 2003 (gmt 0)

10+ Year Member



you might use SSI, or you could use PHP to call the Perl/CGI. I'd tend to favor the PHP method. You can use the system() function.

php docs:
system -- Execute an external program and display output
Description
string system ( string command [, int return_var])

system() is just like the C version of the function in that it executes the given command and outputs the result. If a variable is provided as the second argument, then the return status code of the executed command will be written to this variable.

Warning
If you are going to allow data coming from user input to be passed to this function, then you should be using escapeshellarg() or escapeshellcmd() to make sure that users cannot trick the system into executing arbitrary commands.

Note: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.

The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.

Returns the last line of the command output on success, and FALSE on failure.

If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

Hope that helps,
Scott Geiger

Jscally

9:44 pm on May 13, 2003 (gmt 0)

10+ Year Member



Very thorough, thank you very much. I'll look further into that solution.

ShawnR

8:19 am on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Other methods:

  • Instead of your template including the output of the perl script, have the perl cgi include the template. Something like: Read and spit out template file from the top until you get to "<!--- Perl output goes here --->". Then print the perl output. Then read and print the rest of the template file.

    or

  • Use frames, with the perl output filling one frame, and your template filling the surrounding frames.

Shawn

BCMG_Scott

11:31 am on May 14, 2003 (gmt 0)

10+ Year Member



Good thought ShawnR. I do actually use something similar to your first method. The frames option works, but it's such a pain to get the frames to look just right - always seems like something is slightly off balance.

Scott

ShawnR

1:00 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"...The frames option works, but it's such a pain to get the frames to look just right ..."

Agreed. And there are all the problems associated with frames, such as the back button not working well...