std_print_a

From WeBWorK
Jump to: navigation, search


std_print_a -- plugin method used in "List.pm" type objects

Description

This is an example of a subroutine ( i.e. a subroutine whose first argument is a reference to a parent object ) which defines how the list of answers is printed from a [/docs/docs/pglanguage/pod/list.html List.pm] object.

Syntax

std_print_a( $self, @array)

Params

$self is a reference to the parent list object and can be used to reference preferences stored there.
@array is the list of answers to be displayed.

Action

For this example the answers are listed in vertically in an ordered list, indexed by capital letters beginning with "A"

Returns

A string, containing the answers, properly formatted.

Examples


$ml = new_match_list();
$ml->rf_print_a(~~&std_print_a); # set the answer format for this list object to use the std_print_a subroutine
# enter three questions and their answers
$ml->qa( "What color is a rose?",
"Red",
"What color is the sky?",
"Blue",
"What color is the sea?",
"Green"
);
# choose two of these questions, ordered at random,
# which will be printed in the problem.
$ml->choose(2);
BEGIN_TEXT
Match the answers below with these questions:$BR
\{$ml->print_q\} Print the questions$BR
Answers:
\{$ml->print_a \} Print the answers

END_TEXT

ANS( $ml->ra_correct_ans() ); #submit the correct answers

Notes

Defined in [PGchoicemacros.pl]
follow us