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

I have two questions in one.
1) I recently inquired about using Javscript.pm here javascript, javascript.pm, data::Javascript, cgi, installing, using, perl module from cpan and I had a problem with all the ways of doing it; What am I missing there or is there another way.

2)When I use a script and I set a Environment variable i do this

#!/usr/bin/perl $ENV{HTTP_HOST} = "http://www.perlmonks.org"; $ENV{SERVER_NAME} = "http://www.perlmonks.org"; $ENV{SCRIPT_URI} = "/cgi-bin/gg.cgi"; foreach $var_name ( sort keys %ENV ) { print "<p><b>$var_name</b><br>"; print $ENV{$var_name}; }
These of course are samples above. Is this the RIGHT WAY to set environment variables for a current page; or is there a RIGHT or BETTER way; also when i use the print while statement above am I getting the right info as the browser or the server would have or is the "while print" distorted by my declarations above "EG. $ENV{}>

  • Comment on $ENV{HTTP}, environment variables, javascript, javascript.pm, setting for a current page
  • Select or Download Code

Replies are listed 'Best First'.
Re: $ENV{HTTP}, environment variables, javascript, javascript.pm, setting for a current page
by chromatic (Archbishop) on Mar 31, 2001 at 06:19 UTC
    I can't speak to #1 because you haven't given enough information. Perhaps you can reply to your post with error messages or more detail than saying "I had a problem".

    As for #2, the right way to set those environmental variables is to let the web server set them. If you're providing those only as an example of environmental variables you want to set, then, yes, that is the correct way to set them.

    I don't entirely understand your question about the print statement. If you want to display what the *web server* set for the SERVER_NAME or SCRIPT_URI, then assigning them new values before you print them is guaranteed to clobber the original settings.

    Another helpful tip -- using the -w and -T flags and the strict module is highly recommended when writing CGI scripts. It will save you much grief in the future.

Re: $ENV{HTTP}, environment variables, javascript, javascript.pm, setting for a current page
by strredwolf (Chaplain) on Mar 31, 2001 at 06:29 UTC
    On #1, I really can't say unless you host is very restrictive on modules, and runs an old (Pre-5) version of Perl. UGH!

    On #2, Unless you're testing CGI scripts, I would let the server set them. If you are, I'd pull mhttpd or something similar (aka a light-weight web server) and install that to test your scripts on. Anything was tested on mhttpd.

    --
    $Stalag99{"URL"}="http://stalag99.keenspace.com";

Re: $ENV{HTTP}, environment variables, javascript, javascript.pm, setting for a current page
by heyman (Novice) on Mar 31, 2001 at 11:15 UTC
    Yes here is the error message I get when i run my script.
    Perl error was Can't locate URI/javascript.pm in @INC (@INC contains: /usr/local/webserver/perl/lib/5.6.0/IP27-irix /usr/local/webserver/perl/lib/5.6.0 /usr/local/webserver/perl/lib/site_perl/5.6.0/IP27-irix /usr/local/webserver/perl/lib/site_perl/5.6.0 /usr/local/webserver/perl/lib/site_perl

      In your other question, you mention that you're using Data::Javascript. It appears from your error message that you're trying to call URI::javascript (and there is no such beast on CPAN).

      Perhaps if you posted your code (cut and paste), along with the error message, then we could better help.