Include Perl in Questions
You can use the <eqn> and <EQN> tags to include one or more Perl statements in your questions. The value of the last Perl statement in the <eqn> or <EQN> tag is returned by the tag when the question is used.
Understanding the <eqn> and <EQN> Tags
The <eqn> and <EQN> tags are WebAssign tags that let you put Perl statements in your questions. Most often, these statements are used to set or read the values of variables in order to make the question behave in a certain way.
For example, to change the size of the answer box for numerical or fill-in-the-blank questions, you would add this code to Answer:
<EQN $size=5; ''>
This code consists of three parts:
- The <EQN> tag itself, which tells WebAssign that the enclosed values should be processed as Perl statements.
- The first Perl statement,
$size=5;which assigns the value 5 to the WebAssign variable $size, which is used to specify how wide the answer box should be.
- The second Perl statement,
''which is an empty string. Because the result of the last Perl statement is always included in your question, answer key, or solution (depending on where the code occurs), the empty string is often used as the last statement.
Both the <eqn> and <EQN> tags include Perl statements, but they display values differently depending on whether they are used in Question, Answer, or Solution.
|Intended Use||Use in Question and Solution.||Use in Answer.|
|Display in Question and Solution||A circle of radius 5 has area 78.5398163397448.||A circle of radius 5 has area 78.5398163397448.|
|Behavior in Question and Solution||
|Display in Answer||A circle of radius 5 has area 78.5.||A circle of radius 5 has area 78.5398163397448.|
|Behavior in Answer||
Paired and Unpaired Forms
Both the <eqn> and <EQN> tags can be used in paired and unpaired forms.
- The unpaired form consists of a single tag and is used most frequently to
display values or in Answer. It has the following syntax
(using either eqn or
<EQN perl_statement; perl_statement>
- The paired form consists of an opening tag and a closing tag and is usually used
to include longer blocks of Perl statements. It has the following syntax (using
either eqn or
<eqn> perl_statement; perl_statement </eqn>Note: If your Perl statements include the greater-than character (>), you must use the paired form.
- If needed, open your question in the Question Editor.
Start the <eqn> or <EQN> tag.
You can use either the paired or unpaired form, as described above.Best Practice:
- In Question or Solution, use <eqn>.
- In Answer, use <EQN>.
Type the Perl statements that you want to perform.
- To ensure the security of the WebAssign service, some Perl functions are not supported.
- The Perl newline character (\n) does not work in WebAssign. Instead, include the HTML <br> tag where you need a line break. You must use the paired form of the <eqn> or <EQN> tag.
End each Perl statement except for the last one with a semicolon (;). The value returned by the last statement is displayed as part of your question or answer key.Tip: Use two single quotes ('') as your last Perl statement if you do not want any value displayed by your code.
End the </eqn> or </EQN> tag.
- When using paired tags, the ending tag must match the start tag. You cannot, for example, start with <eqn> and end with </EQN>.
- When using the unpaired form, do not add a slash at the end of the tag as with XML tags. Just use the closing angle bracket (>).
Example Multiple-Choice Question Using <eqn> and <EQN>
The following table summarizes an actual question.
|Display to Students|