[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] where to put subroutines



Jeffrey Hull wrote:
[snip]
>When I call the script below from the browser (IE4.5) on the terminal, I get
>
>	# Undefined subroutine &main::mime called.
>	File 'Server:MacHTTP 2.2.2:MacHTTP Software &
>	 	Docs:Nurses:cgi-bin:phone.acgi'; Line 6
>
>Here is the problem script, properly saved from MacPerl as a cgi script
>named "phone.acgi"
>
>	#!perl -w
>
>	require "";
># no problems known here; resides at
># MacPerl Ÿ:lib:subparseform.lib
>
>	&Parse_Form; 		#copied from E. Castro's book
>
>	&mime;			#here is the little lost subroutine
>
>	&header;
>
>	#hoping I could get some response to prove it was functional
>	print "$ENV{'REQUEST_METHOD'}\n";
>
>	&footer;
>
>
>And the admittedly trivial practice subroutines (stored of course as
>separate files "mime" "header" "footer")
>
>	sub mime {
>		print "Content-type: text/html\n\n";
>		}
>
>	sub header {
>		print "<html><head><title>Test Page</title>
>		<STYLE> BODY { font-family: Arial; font-size: 9pt }
>		</STYLE></head>\n";
>		print "<body>\n";
>		}
>
>	sub footer {
>		print "</body></html>";
>		}
>

Every subroutine must be in the same file as the script, or it must be
brought into the script by way of 'use' or 'require', which do different
things when you employ them. I suggest you start simple, though, and just
put everything into one file.

Try this, saved as phone.acgi, with the path you use in your html form's
action attribute:
#Script starts below, not including this line:

#!perl -w

# require ""; 	#This doesn't really do anything


# &Parse_Form; 	# I'm leaving this out for now;
		# Same issues apply.

&mime;	# This is where your script poops out, because
	# it has no way to know what you mean;
	# "&main::mime" means a subroutine 'mime' in the main
	# package, which is _this_ script.
	# I've put it below.

&header;

print "$ENV{'REQUEST_METHOD'}\n";

&footer;


sub mime {
print "Content-type: text/html\n\n";
}

sub header {
print "<html><head><title>Test Page</title>
<STYLE> BODY { font-family: Arial; font-size: 18pt }
</STYLE></head>\n";
print "<body>\n";
}

# A different way to quote multiple lines (a 'here-doc')
sub header1 {
print <<HEAD;
<html><head><title>Test Page</title>
<STYLE> BODY { font-family: Arial; font-size: 18pt }
</STYLE></head>
<body>

HEAD
}

sub footer {
print "</body></html>";
}

# Script ends above, not including this line.

Keep trying!


- Bruce

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Bruce Van Allen
bva@cruzio.com
831/429-1688
P.O. Box 839
Santa Cruz, CA  95061

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org