DAMN THESE QUOTES!!

A

amerar

Can anyone tell me what the heck is wrong here? This looks ok to me,
as it works from a normal html document.

but if my Perl program tries to print it, I can a syntax error:

print qq^<script language='javascript'>\n^;
print qq^<!--\n^;
print qq^if (!document.layers) {\n^;
print qq^ document.write("<input type=button
onclick=popUpCalendar(this, 'Party_Details.PartyDate, "mm/dd/yyyy")'
value='Select' style='font-size:11px'>")\n^;
print qq^}\n^;
print qq^//-->\n^;
 
S

Scott Bryce

Can anyone tell me what the heck is wrong here? This looks ok to me,
as it works from a normal html document.

but if my Perl program tries to print it, I can a syntax error:

Is PERL giving you the syntax error, or is the JavaScript interpreter
giving you the syntax error? I suspect you want to post the output from
your script to a JavaScript newsgroup and ask your question there.

print qq^<script language='javascript'>\n^;
print qq^<!--\n^;
print qq^if (!document.layers) {\n^;
print qq^ document.write("<input type=button
onclick=popUpCalendar(this, 'Party_Details.PartyDate, "mm/dd/yyyy")'
value='Select' style='font-size:11px'>")\n^;
print qq^}\n^;
print qq^//-->\n^;

Why are you using qq^text^? I would think qq(text) would be easier to read.
 
S

Scott Bryce

Scott said:
Is PERL giving you the syntax error,
-----^^^^

Did I just do what I think I did?

The language is Perl. The interpreter is perl. There is no such thing as
PERL. Do I have that right?
 
A

amerar

Even this gives me a syntax error:

print <<JS_END;
<script language=javascript>
<!-- //
if (!document.layers) {
document.write("<input type=button onclick='popUpCalendar(this,
Party_Details.PartyDate, \"mm/dd/yyyy\")' value='select'
style='font-size:11px'>")
}
//-->
</script>
JS_END


It wants some close paren right before the mm/dd/yyyy.........WHY!!!!!
this works FINE in a static HTML page!!
 
S

Scott Bryce

The javascript error is this:

Line 41
Char 95
Expected ')'

You are asking a Javascript question in a Perl newsgroup. Post the
output of the Perl script to a JavaScript newsgroup and ask there.
 
M

Matt Garrish

Even this gives me a syntax error:

print <<JS_END;
<script language=javascript>
<!-- //
if (!document.layers) {
document.write("<input type=button onclick='popUpCalendar(this,
Party_Details.PartyDate, \"mm/dd/yyyy\")' value='select'
style='font-size:11px'>")
}
//-->
</script>
JS_END


It wants some close paren right before the mm/dd/yyyy.........WHY!!!!!
this works FINE in a static HTML page!!

Because you're only escaping the " for perl. My guess is that when this
prints you get:

document.write("..., "mm/dd/yyyy")'

You need to use a double-backslash to get one through for javascript.

Matt
 
M

Matt Garrish

Matt Garrish said:
Because you're only escaping the " for perl. My guess is that when this
prints you get:

document.write("..., "mm/dd/yyyy")'

You need to use a double-backslash to get one through for javascript.

Sent that too quickly. You could alternatively tell perl you want it to
treat the here doc as though enclosed in single quotes by changing:

print <<JS_END;

to

print <<'JS_END';

Then the interpreter won't see your backslashes as trying to escape any
characters.

Matt
 
J

Jürgen Exner

Can anyone tell me what the heck is wrong here? This looks ok to me,
as it works from a normal html document.

but if my Perl program tries to print it, I can a syntax error:

print qq^<script language='javascript'>\n^;
print qq^<!--\n^;
print qq^if (!document.layers) {\n^;
print qq^ document.write("<input type=button
onclick=popUpCalendar(this, 'Party_Details.PartyDate, "mm/dd/yyyy")'
value='Select' style='font-size:11px'>")\n^;
print qq^}\n^;
print qq^//-->\n^;

I cannot reproduce your problem:
C:\tmp>perl -c t.pl
t.pl syntax OK

Apparently there is no syntax error in the code snippet that you posted.

jue
 
B

Brad Baxter

Scott said:
Why are you using qq^text^? I would think qq(text) would be easier to read.

In general, I agree. But I do happen to like ^ as a quote character
whenever others are problematic. I think it's because it sits up
near the top, like ' and ".

print qq^})]>~'"\n^;
 
S

Scott Bryce

Brad said:
In general, I agree. But I do happen to like ^ as a quote character
whenever others are problematic. I think it's because it sits up
near the top, like ' and ".

Understood. But in the OP's code, using () wasn't problematic.
 
T

T Beck

Scott said:
Understood. But in the OP's code, using () wasn't problematic.

True, but in his original post, he had:

print qq^ document.write("<input type=button
onclick=popUpCalendar(this, 'Party_Details.PartyDate, "mm/dd/yyyy")'
value='Select' style='font-size:11px'>")\n^;

While using () here should still result in valid code, I'd still call
it problematic. I think it's a safe move to avoid using a delimeter
that's inside of the quote. It can be more confusing to do so, and
leads to more mistakes editing the quotes and accidentally getting
run-ons. (and might even make your favorite color coding editor angry,
I dunno)

Along those lines, his text has <, {, and ( all spoken for. [] could
have worked, but ^ seems like a decent choice to me.

--T Beck
 
B

Brad Baxter

T said:
Scott said:
Understood. But in the OP's code, using () wasn't problematic.

True, but in his original post, he had:

print qq^ document.write("<input type=button
onclick=popUpCalendar(this, 'Party_Details.PartyDate, "mm/dd/yyyy")'
value='Select' style='font-size:11px'>")\n^;

While using () here should still result in valid code, I'd still call
it problematic. I think it's a safe move to avoid using a delimeter
that's inside of the quote. It can be more confusing to do so, and
leads to more mistakes editing the quotes and accidentally getting
run-ons. (and might even make your favorite color coding editor angry,
I dunno)

Along those lines, his text has <, {, and ( all spoken for. [] could
have worked, but ^ seems like a decent choice to me.

Or, of course, a here doc:

print <<"__";
<script language='javascript'>
<!--
if (!document.layers) {
document.write("<input type=button
onclick=popUpCalendar(this, 'Party_Details.PartyDate, "mm/dd/yyyy")'
value='Select' style='font-size:11px'>")
}
//-->
__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,177
Messages
2,570,954
Members
47,507
Latest member
codeguru31

Latest Threads

Top