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

We are new to Perl but not programming. To start, we got a Perl manual and loaded Sambar server on our laptop so we could test Perl Cgi scripts. We wrote a simple script that accepts data (1 field) from an html form. Here's the script:
#!C:\perl\bin\perl -w # Script: form1test.pl works with form1test.html use strict; use CGI ':standard'; my $value; $value = param('yourname'); print "content-type: text/html\n\n"; print "The name you entered is $value";
Problem: When we run form via localhost, we hit submit and the browser comes back with Page Not Found. If we take out the -w on line 1 and comment out some of the lines, the script will execute (but obviously the $Value will not display as it has been removed). Is Sambar an acceptable server?( We run Windows-XP Pro) Or should we use another Server for localhost? Here's the modified script that does work:
#!C:\perl\bin\perl -w # Script: form1test.pl works with form1test.html #use strict; #use CGI ':standard'; #my $value; #$value = param('yourname'); print "content-type: text/html\n\n"; print "Your Name will display here";
Thank you in advance. John

2006-07-07 Retitled by Corion, as per Monastery guidelines
Original title: 'New To Perl'

Replies are listed 'Best First'.
Re: Configuration of Sambar server to use Perl
by CountZero (Bishop) on Jul 06, 2006 at 17:26 UTC
    Thus said the Sambar docs:

    Using Perl

    When the Sambar Server executes a Perl CGI application (*.pl files found in the CGI directory), the perl.exe executable found in the perl subdirectory of the Sambar Server installation is used.

    So it appears that the #!C:\perl\bin\perl -w line is probably not pointing to the correct Perl-executable and therefore may break when it tries to use the CGI-module.

    CountZero

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

Re: Configuration of Sambar server to use Perl
by cowboy (Friar) on Jul 06, 2006 at 15:31 UTC
    A page not found error is generally related to the webserver. Check where your form is actually submitting to. As an unrelated note about style, it's probably better to use
    print header();
    instead of
    print "content-type: text/html\n\n";
    That way you're sure you'll get a proper header.
Re: Configuration of Sambar server to use Perl
by andyford (Curate) on Jul 06, 2006 at 15:32 UTC
    I would check the Sambar documentation to see if it needs some configuration settings made to allow CGIs to run.
Re: Configuration of Sambar server to use Perl
by Moron (Curate) on Jul 06, 2006 at 16:51 UTC
    The usual reason for this problem, irrespective of type of webserver, is that the cgi program is not installed where the webserver expects it to be. In the case of Sambar, a little googling tells me it gets delivered with a sample cgi program called 'environ.pl'. A crude and dirty approach would therefore be to put the program in the same place as that one. The Sambar documentation ought to tell you more about aliasing and configuring paths for a cleaner approach - as it happens I only use apache on linux which uses a config file for aliasing paths, but the principles will be very similar.

    -M

    Free your mind

      Hello, thanks for commenting. I uninstalled Sambar and installed Apache on windows. When I type in  http://localhost I get back the Sambar main screen, not apache. Is there some way to tell localhost that apache is now the localhost?

      Thank you. John

        hmmmmmm
        Based on your initial question and your latest node (above) I think you have a rather larger problem than you think.

        Given your description above, it appears that either...

        1. You did NOT actually uninstall Sambar server
                or
        2. your browser cached what Sambar last rendered from http://localhost and is not set up to recheck for updates
                AND
        3. You really need to study and understand some "user" fundamentals
        First you need to ensure Sambar is not running. The correct installation and configuration process (including paths) for Apache is too long to put in a post but is available here: v2.2

        -M

        Free your mind

Re: Configuration of Sambar server to use Perl
by imp (Priest) on Jul 06, 2006 at 17:26 UTC
    The problem with including -w could be that sambar isn't aware that this is a flag, and it thinks that this is part of the executable name.

    Try doing 'use warnings;' instead.

    As for commenting out use CGI;, perhaps your include path is lacking? Try this to see what you have currently:

    #!C:\perl\bin\perl.exe print "Content-type: text/plain\n\n"; print "Include path:\n"; print "$_\n" for @INC;
Re: Configuration of Sambar server to use Perl
by Anonymous Monk on Jul 06, 2006 at 19:14 UTC
    Perhaps I'm missing some new feature of the CGI module, but I don't see the creation of a CGI object from which to call the param method. You should also check your server's error log for perl related errors such as those mentioned in above posts. The line: use CGI::Carp qw(fatalsToBrowser); can make locating these errors easier while you are developing your program.
      He imports the param fuction with the ':standard' argument.
      I usually say use CGI ('param'); because I only care about that function. This allows me to say $x = param('x') without having to be bothered with objects.
Re: Configuration of Sambar server to use Perl
by holli (Abbot) on Jul 06, 2006 at 15:20 UTC
    You don't need a SAMBA server. You need Apache or another webserver!


    holli, /regexed monk/

      Not SAMBA. Sambar - it is a web server :-)

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        Ouch.


        holli, /regexed monk/