[thelist] Re: Trying to include multiple JavaScript files in a perl script...

Keith cache at dowebs.com
Fri Nov 30 14:32:23 CST 2001


> >  >I'm trying to include a .js file into a cgi script (that produces
> >  >HTML output for the browser, obviously)...

> One of the things I'm trying to put into the script, along with the
> rest of the HTML formatting it allows you to put, is a call to a JS
> file. Like so: <SCRIPT LANGUAGE="JavaScript1.2"
>         SRC="/HM_Loader_seconds.js"
>         TYPE='text/javascript'>
> </SCRIPT>
> 
> hmm...I wonder if the quotes (single and/or double) are causing it to
> choke....

That's probably the case. You might want to graduate up to Perl5 
block quoting syntax, from using double quotes to using the "here 
document" method of quoting. You ca print entire HTML documents 
with one set of quotes. A familiar use found in CPAN modules is

print <<HERE <SCRIPT LANGUAGE="JavaScript1.2"
 SRC="/HM_Loader_seconds.js"
 TYPE='text/javascript'>
</SCRIPT>
HERE

The << can be any 2 same characters followed by a string where 
the same string on a line all by itself ends the quote block. This will 
execute any scalars found within the block but you can single quote 
and double quote all you want inside the block.

Personally I use a variation for block quoting that can be either 
single or double quoted and does not require the ending to be on a 
separate line.
 
print qq~$something

$again~; 

is a double quote and will print the value of $something and two 
lines later the value of $again (new line breaks are maintained as if 
you had used "$something\n\n$again";)

print q~$something

$again~;

is a single quote that prints literally $something and $again without 
executing the scalers. The trick on this variation is that the quote 
indicator must be qq or q and the quote block boundaries can be 
most any punctuation other than $. 

I print all kinds of js out from perl everyday so it's not uncommon.

Regards
keith






More information about the thelist mailing list