malaga has asked for the wisdom of the Perl Monks concerning the following question:

this is NOT a javascript question. i tried asking this question on the chatterbox, but i don't think i'm asking it right. the question is: i want my perl script to print out javascript, just like it would print out html. i've been told it's possible. i've tried using <<'HERE'; but i got a blank screen (and no error messages). Do I need to escape everything, or is this impossible in the first place? I've looked around for examples, but can't find any. Can anyone point me in the right direction?
#!c:/Perl/bin/Perl -wT use strict; use CGI qw/:standard/; print header; print "can you hear me"; #this does print, nothing else does print "<html>"; print "<head>"; my $javascript = <<'TOAD'; <style> <!-- all.clsMenuItemNS{font: bold x-small Verdana; color: white; text-decor +ation: none;} .clsMenuItemIE{text-decoration: none; font: bold xx-small Verdana; col +or: white; cursor: hand;} A:hover {color: red;} --> </style> TOAD print "</head>"; my $javanext = <<'FROG'; <script language="JavaScript" src="/menu.js"> </script> <script language="JavaScript" src="/menucontext.js"></script> <script language="JavaScript"> showToolbar(); </script> <script language="JavaScript"> function UpdateIt(){ if (document.all){ document.all["MainTable"].style.top = document.body.scrollTop; setTimeout("UpdateIt()", 200); } } UpdateIt(); </script> FROG print "</HTML>";

Replies are listed 'Best First'.
Re: print html/javascript
by dws (Chancellor) on Apr 02, 2001 at 03:41 UTC
    Your script sets $javascript to one multi-line string, and $javanext to another, but you never print them.

    To resolve this, replace   my $javascript = <<'TOAD'; with   print <<'TOAD'; and   my $javanext = <<'FROG'; with   print <<'FROG';

    (And I assume you left off the <body>..</body> tags so that you could post a smaller example.)

      oh sh__. it's always something stupid. thanks. this worked beautifully. (yes, i just shortened it all up for the post. )
Re: print html/javascript
by nysus (Parson) on Apr 02, 2001 at 04:46 UTC
    I learned by lesson with here documents yesterday:

    Get rid of all leading and trailing white space around the print <<'TOAD' and 'TOAD'lines or you will get an internal server error.

      Remember kiddies:
      my $name = 'cLive ;-)'; # interpolated print <<"_END_"; # or <<_END_ - quotes optional My name is $name. _END_ # prints 'My name is cLive ;-)' # not interpolated print <'_END_'; My name is $name. _END_ # prints 'My name is $name'
      And remember, quoted << 'here' text must end with the token used on a line on its own, with no trailing whitespace.

      Finally, also remember to escape the @ (ie \@) in an e-mail address contained in web page output that will be interpolated (I always forget that one :)

      cLive ;-)