Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm new to Perl and I'm trying to get Frontpage 2000 to call a Perl script via a link. It runs the Perl script fine until I add HTML coding. What commands do I need in my Perl script to allow me to add HTML formatting. Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: Frontpage 2000 and CGI
by CountZero (Bishop) on Feb 03, 2004 at 21:08 UTC
    What do you mean by "until I add HTML coding"?

    In your Perl script, you basically print your HTML (or whatever you want to send to the browser), but you will have to take care to add the right headers and things like that.

    Unless you want to re-invent the wheel I suggest that you explore the CGI-module which has all of this (and much more).

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      Basically if I just call the perl script from frontpage it runs in a dos window and then returns. I'm just trying to display the information within the browser using html formatting. I have no idea how to put the header information in to allow the page formatting to work. Right now it partially works with statements I've found in other scripts but it prints the lines of code rather than the output. What do I need in the perl script to use the CGI module and allow the page to display correctly.
      #!c:\perl print "Content-type:text/html\n\n"; print <<WEB_PAGE; <html> <title>Perl Script Directory</title> <h1>Directory of c:\temp</h1> WEB_PAGE $dir = "C:\\temp"; unless (opendir(DIR, $dir)) { &print_msg("\tCan't open $dir\n"); closedir(DIR); exit(0); } foreach (readdir(DIR)) { # don't include current dir or parent next if $_ eq '.' || $_ eq '..'; $path = "$dir/$_"; if (-d $path) { next; #&traverse($path); # check to see if file } elsif (-f _) { #if (!copy($path,"\\\\$Machine\\$Share{netname}\\temp\\")) { # &print_msg("FAILED ($path) " . Win32::Lanman::GetLastErro +r() . "\n"); #} else { # &print_msg("."); #} #print "<P $path>\n"; print $path; } } sleep (10); print "</html>\n";

      Edited by BazB: added code tags.

        Of course you will have to run your webpages within a real webserver or else it will not work. You Perl script is now more or less hanging in the air (hence you see it running in a "dos"-window, but the output is not going to your browser) and this has nothing to do with HTML-formatting.

        So you will have to set up a real webserver (not the HTML renderer which Frontpage uses to show your HTML-page).

        The easiest way to set up your own webserver is to install a free Apache webserver, which you can find here (all configured so it runs straight out of the box).

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Frontpage 2000 and CGI
by NetWallah (Canon) on Feb 03, 2004 at 22:37 UTC
    Aah - I think I see what you are trying to do - you are trying to run a CGI page inside for Frontpage .. that won't work.

    A CGI app MUST run in the context of a web server like IIS or Apache. You could run the CGI app as a command-line application, in which case it will give you HTML output to the STDOUT, which can look fairly ugly.

    So - botton-line - test your Frontpage-developed web after publishing it to a web server.

    "When you are faced with a dilemma, might as well make dilemmanade. "

Re: Frontpage 2000 and CGI
by MCS (Monk) on Feb 03, 2004 at 21:57 UTC

    Perl is not like javascript or php... your browser does not run the program. Instead, you need to have a web server somewhere. (either on your machine or a remote machine). I haven't used windows in a while but I imagine it shouldn'e be too hard to install apache: http://www.apache.org/ and then that would give you a cgi-bin/ directory to put your scripts in. Then you would point your browser to something like http://localhost/cgi-bin/perlscript.pl

    The other thing you can do for testing purposes, is run your program and save the output to a file. In unix you would do: "./perlscript.pl > output.html" and then open up output.html in a browser. I'm not quite sure how to do it in windows. Maybe someone who uses windows can help you there.

      Perl is not like javascript or php... your browser does not run the program.

      Huh? Your browser runs PHP?



      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
      =~y~b-v~a-z~s; print
        well the browser doesn't "run" the php but it is imbedded into your html file. (quite unlike perl where it is in a /cgi-bin/ directory)
Re: Frontpage 2000 and CGI
by Plankton (Vicar) on Feb 03, 2004 at 22:07 UTC
    Do not use Frontpage ... it is a crutch and will make your mind weak!

    Plankton: 1% Evil, 99% Hot Gas.