# Perl Questions...



## martinatkinson (Feb 17, 2002)

Hello!

Forgive me if this post is in the wrong category, this section seemed to suit my questions best

I have a Perl file called "registrate.cgi" and an HTML file called "response.html"  Right now to print an HTML file I need to type:
	
	



```
print "<html><body>".
      "<!--Content is here-->".
      "</body></html>";
```
  What I would like to do is to have the CGI script print the contents of the HTML file "response.html" instead of me having to hard code the source into the script.  I know this is possible but I can not find out how to do it.  Can anyone help?

Thanks and have  a great day!

Albert


----------



## gumse (Feb 17, 2002)

system("cat filename.html");


----------



## martinatkinson (Feb 17, 2002)

Hmmm, I must be doing something wrong.  This does not seem to work.  Here is what I have:
	
	



```
#!/usr/bin/perl -T

print "Content-type: text/html\n";
print "\n";

system("cat /mt/index.html");
```
  Is this correct?

Thanks for your help!

Albert


----------



## gumse (Feb 17, 2002)

In principle it should work.
But the path "/mt/index.html" seems weird, I don't think you have a /mt at the root level.
What kind of error do you get ?


----------



## martinatkinson (Feb 17, 2002)

Hello!

I do not get any errors at all.  It loads the CGI file as nothing, no source code or nothing, just a white screen.  Does this need to be the absolute path to my file or what?

Have a great day!

Albert


----------



## gumse (Feb 17, 2002)

Try to run the Perl program from the shell prompt, then you should see the output.
I think you need to use the absolute path to the file.


----------



## martinatkinson (Feb 17, 2002)

Hello!

How would I run the script from the terminal?

Thanks!

Albert


----------



## gumse (Feb 17, 2002)

If you made the file executable (as you must with cgi's) then cd to the place where the file is located, then type ./filename.cgi


----------



## martinatkinson (Feb 17, 2002)

Hmm, still does not seem to work, here is the updated code in my "test-c.cgi" script:
	
	



```
#!/usr/bin/perl -T

print "Content-type: text/html\n";
print "\n";

system("cat /Library/WebServer/Documents/index.html");
```
  Here is the error I get when I acess the script in my browser:
	
	



```
[Sun Feb 17 16:29:17 2002] [error] [client 127.0.0.1] Premature end of script headers: /Library/WebServer/CGI-Executables/test-c.cgi
```
  And here is a copy of what my terminal looked like after I tested it from there:
	
	



```
[localhost:/Library/WebServer] albertat% cd /Library/WebServer/CGI-Executables
[localhost:/Library/WebServer/CGI-Executables] albertat% ./test-c.cgi
[localhost:/Library/WebServer/CGI-Executables] albertat%
```
  Any suggestions?

Thanks for your help!

Albert


----------



## gumse (Feb 17, 2002)

I tested this one:
-----
#!/usr/bin/perl
print "Content-type: text/html\n";
print "\n";
print "START START\n\n";
system("cat /Library/WebServer/Documents/index.html");
print "\nEND END\n\n";

-----
Works ok, but with the -T option system calls don't seem to be allowed.

How did you create your perl script ?
You must be sure that it has unix line endings.


----------



## martinatkinson (Feb 17, 2002)

Hello!

Ok, I must be doing something wrong, now it comes up with the error:
	
	



```
[Sun Feb 17 17:28:51 2002] [error] (2)No such file or directory: exec of /Library/WebServer/CGI-Executables/test-c.cgi failed
[Sun Feb 17 17:28:51 2002] [error] [client 127.0.0.1] Premature end of script headers: /Library/WebServer/CGI-Executables/test-c.cgi
```
  I just copied the script that you showed me and that is what I got.  By the way I am running an Apache web server and am using TextEdit to make my CGI files just saving it as plain text with the extension .cgi.

Any suggestions?  Sorry to keep bugging you.

Have a great day!

Albert


----------



## gumse (Feb 17, 2002)

It's textedit that plays trix on you.
The file must be saved in "raw" text format with unix line endings.
You shuld use BBEdit, or if you are cli-inclined, try vi.

I'm running a swedish system right now, so i'm not sure about the menu names in the US textedit, but in the "Format" menu you have an option to make a file "Pure Text" or something like that , with no formatting and unix line endings. This should work.


----------



## martinatkinson (Feb 18, 2002)

Hello!

This still does not seem to work.  I have tried various text editors with no luck.  Thanks for trying to help me out, I appreciate it alot.  I guess I will just have to learn more about Perl before doing this  

Have a great day!

Albert


----------

