1

The google API example shows that you should have the javascript within the head tag but I am using perl module CGI and in there they suggest that you use "print header;" instead of writting out your headers explicitly.

So if I want to use the perl CGI module and the google API javascript what is the correct way to do this?

I tried writing out the header explicitly but It seemed like the perl module really wanted me to use the header method. It seems like this would be a common use case but I looked around the web for some examples of this and I could not find one. Any help would be appreciated.

3
  • Did it work when you wrote out the header explicitly? That's the important thing. Commented Jun 11, 2010 at 22:30
  • It did not work when I wrote out the header explicitly but I do not have access to the server log right now. When I get back home I will report what the error said. Commented Jun 11, 2010 at 23:26
  • After a little bit of playing with it I find my main issue was a very newbee problem where my first line was not the "Content-Type: text/html\n\n". So I am not using CGI very much at all and it seems to be working well. Commented Jun 12, 2010 at 5:21

1 Answer 1

2

Just ignore the CGI documentation and print your own HTML head section with the <script> section.

By the way, the header function in CGI prints the HTTP header, not the HTML header. The html header is produced by a function start_html. But you do not need to use CGI's built-in function. CGI output is supposed to look like the following (without the # parts):

Content-Type: text/html                   # HTTP HEADER

<html>                                    # HTML HEADER
<head>
<script type="text/javascript">           # JavaScript
...
</script>
</head>
...
Sign up to request clarification or add additional context in comments.

2 Comments

Should I use the other functions in the CGI module or just write out everything myself? Seems like the CGI module is just getting in the way.
@stephenmm: I wouldn't recommend using the HTML generation routines in CGI.pm. If you have a lot of HTML generation to do, think about using the Template Toolkit (Template module). Otherwise, just use print statements and heredocs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.