Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Unverified Perl & html code

Hi everyone.

If using html tags in unverified perl , do they need to always be enclosed in quotes?

 
[%Begin Unverified Perl
{  
return "<font size=\"1\" face=\"arial\">" ;
}
End Unverified%]


versus

 
[%Begin Unverified Perl
{  
return <font size=\"1\" face=\"arial\">;
}
End Unverified%]
asked Nov 29, 2018 by WTW_cal Bronze (1,595 points)

1 Answer

+1 vote
You will need the surrounding quotation marks for something like this, but this is more than just a rule about surrounding HTML with quotation marks - this is about how programming languages handle text.

Perhaps an example would be useful.  Try putting these two JS scripts on two pages and see how the resulting behavior differs:

<script>
var xyz = "hello";
alert(xyz);
</script>


<script>
var xyz = "hello";
alert("xyz");
</script>


On line 3 of the first snippet, we haven't included quotation marks around the xyz.  This tells the code that we don't want to literally print "xyz," but instead we want the code to go look at the value behind a variable named "xyz" and print that out instead.  Therefore, this alert displays "hello."

On line 3 of the second snippet, we have added quotation marks around the xyz.  This tells the code that this is the exact value that we want printed out - the code doesn't care whether or not a variable named "xyz" even exists.  Therefore, this alert displays "xyz."

Now let's apply this thinking to the code you posted.  Line 3 of your first example tells the Perl that "<font...>" is the exact value you want to print out to the page, and the Perl is more than happy to do exactly that.

But on line 3 of your second example, the value is not surrounded by quotation marks, so Perl is going to try and treat this like code.  It will see the "<" and think it needs to do a less-than test, it will see the "font" and think it is referring to a variable with that name, and so on.  Ultimately, Perl wants to run this line as code, is unable to do so, and crashes.

Does that make sense?  There are some additional nuances to this, but I hope this helps you understand why the quotation marks are needed in your code.
answered Nov 29, 2018 by Zachary Platinum Sawtooth Software, Inc. (181,275 points)
Great explanation!
...