WeBWorK Problems

Using multidimensional arrays

Using multidimensional arrays

by Sergio Chaves -
Number of replies: 1

I am trying to implement a problem where a variable is selected from a 2D-array of strings
An error is raised when defining the variable that points to the (i,j)-entry. Does WW support 2D arrays as PERL does?
or am I missing something here? I haven't been able to find too much documentation on multidimensional arrays besides the use of matrices.
(Sample code below)
Thanks


DOCUMENT();
loadMacros( "PGstandard.pl", "PGchoicemacros.pl", "PGunion.pl", "choiceUtils.pl", "PGcourse.pl", "PGML.pl", );

@items = ( ['book', 'pen', 'pencil'],
              ['Bat', 'Ball', 'Stumps'],
              ['snake', 'rat', 'rabbit'] );
$word = @items[1][1];
TEXT(beginproblem());
# Main problem

Context()->texStrings;

BEGIN_PGML

Type in the word [$word] into the answer box
[_]{$word}


END_PGML
ENDDOCUMENT();

Error messages

ERRORS from evaluating PG file:
syntax error at (eval 3065) line 66, near "]["

Error details


In reply to Sergio Chaves

Re: Using multidimensional arrays

by Glenn Rice -
You have a Perl syntax error. $word = @items[1][1]; should be $word = $items[1][1];