in reply to Re^3: Testing scripts
in thread Testing scripts

Maybe you don't have a newline after ending_print_tag? Otherwise, please show the full code that exhibits that behaviour, and please put it in between <code>...</code> tags so it renders and downloads nicely.

Replies are listed 'Best First'.
Re^5: Testing scripts
by zealf (Novice) on Feb 13, 2010 at 09:35 UTC
    Ok, thanks for your prompt reply here.
    Any ideas?
    #!/usr/local/bin/perl print"Content-type:text/html\n\n"; print<<"ending_print_tag"; <html> <head> <title>My first CGI</title> <background="#oooooo" text='#FF0000"> </head> <body> <h1>My First CGI</h1> <em>HELLO, INTERNET!</em> <hr noshade> Watch our cyber space, another programmer is on the loose ;-) </body> </html> ending_print_tag

      Did you follow my advice of making sure that there is a newline at the end of your file?

      Your code works for me if it has a newline at the end, and it fails like you described if it does not have a newline at the end. One way to also make it work is to add a comment at the end of the file:

      #!/usr/local/bin/perl print"Content-type:text/html\n\n"; print<<"ending_print_tag"; <html> <head> <title>My first CGI</title> <background="#oooooo" text='#FF0000"> </head> <body> <h1>My First CGI</h1> <em>HELLO, INTERNET!</em> <hr noshade> Watch our cyber space, another programmer is on the loose ;-) </body> </html> ending_print_tag # This is the end of the file and to make sure that we have a newline +after the end of the # here-doc marker.
        Guess this would be my transition from beginer to learner. lol
        Actually have all my scripts so far working now.
        Thanks for your input there, but can I ask another question?
        On these tutorial scripts we have been given a nice little script for organising the name/value pairs into an associative array, ie
        sub ReadParse { local (*in)=@_if @_; local ($i, $loc, $key, $val); #Read in text if($ENV{'REQUEST_METHOD'}eq"GET"){ $in = $ENV{'QUERY_STRING'}; }elsif ($ENV{'REQUEST_METHOD'}eq "POST"){ read(STDIN,$in, $ENV{'CONTENT_LENGHT'}); } @in = split(/&/.$in); foreach $i (0..$#in){ #Convert pluses to spaces $in[$i]=~s/\+//g; #Split in to key and value. ($key, $val)= split(/=/,$in[$i],2);#splits in the first= #Convert%XX from hex numbers to alphanumeric $key=~s/%(..)/pack("c",hex($1))/ge; $val=~s/%(..)/pack("c",hex($1))/ge; #Associate key and value $in{$key}.="\0"if (defined($in{$key})); #\0 is the mulitple separa +tor $in{$key}.=$val; } return 1;#just for fun }
        I just need to now how it fits in between the html forms and the cgi scripts.
        Does the html form reference this and inturn this references the cgi programme?
      Double-check your host's docs for any information about the location of their perl binary. There's a strong chance that it may be at /usr/bin/perl rather than /usr/local/bin/perl, since it would have been installed as part of the operating system instead of a "local" addition. If that path is wrong, then it doesn't matter if your Perl is perfect because the web server process won't be able to find the perl binary to execute it.
        Good point, this code however I was testing on my own Win machine with a command line. My host's cpanel lists
        /home/themanin/perl #as the path to use #the following is used within the script. BEGIN { my $base_module_dir = (-d '/home/themanin/perl' ? '/home/themanin/ +perl' : ( getpwuid($>) )[7] . '/perl/'); unshift @INC, map { $base_module_dir . $_ } @INC; } #although in saying this the FAQ side advises... * Path to Perl: /usr/bin/perl * Path to Sendmail: /usr/sbin/sendmail * Home Directory: /home/your_username/
        I'm slowly narrowing things down here. The latest error I"m getting is
        [Sat Feb 13 04:01:14 2010] [alert] [client 119.12.114.196] /home/thema +nin/public_html/cgi-bin/.htaccess: Invalid command '+ExecCGI', perhap +s mis-spelled or defined by a module not included in the server confi +guration
        I'm sinking, help help. lol