I'm doing a random quote on my site that is powered by perl(duh!) and javascript. I've got everything worked out, except if a document.writein() is too long the browser will produce an error. How can I use perl to limit the size printed into javascript.

I do understand that. But I wrote a perl program that prints random quotes. My perl has no errors, no problems. Basicly this is how it works, it opens the file with the quotes in it. Each quote is seperated by |. So it splits the file up with this. Then I run the following (perl)command: print "document.writeIn(\'$quote\');"; When I load the script it works just fine. However when I run it on my site (<script src=location.pl"></script>) it(the browser) produces the error: unterminated string constant.

What I want to know is: is there a way(in perl) to limit the var $quote to xx amount of charecters? And if $quote goes over can I split it up? Changing each quote to fit size restrictions is impractical, there are over 43,000 of them. :)

I think your problem could be due to the quote having an apostrophe in it. I'm not well-versed on figuring out JavaScript's error messages (or rather, a given browser's interpretation of a JavaScript error message), but this could be a definite possibility.

Perhaps you should backslash all ' characters in the quote before you display it, or perhaps you should use "..." around the quote:

Already ahead of you. That was one of the first things I did. Both browsers(NS & IE) limit the size javascript can print. Which is what that error is(I'm better @ javascript than perl ) What I want to do is stop the error all together by limiting the size of the var $quote. I know that length($quote) would return the no of charecters in the string. But how can use this? I can't just do: split(/length($quote)\10/, $quote); can I?

That way the postition is allways moving. With this updated code it works great! However, my javascript-phobic browser is still producing the same error. When I get home I'll try it on NS, and that IE. Maybe it will turn out differently. If not, I'll take a look my javascript book, which is stupid because document.write is the simplest command!

Must be... I just added one line of code after substr() executed. I had it print out the value of quote after substr did its stuff, and $quote didn't change. I'm just glad to know how I can use substr()!