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

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.

Replies are listed 'Best First'.
Re^7: Testing scripts
by zealf (Novice) on Feb 14, 2010 at 06:07 UTC
    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?

      In short, throw away the whole routine and just use CGI instead. It will be a good, tested routine to deparse a query string into its parameters and it can even return you a hash (what your instructors seem to be calling an "associative array", which is a term used by those raised in Perl4, or awk+sed) should you want so.