WeBWorK Problems

Q: list of lists

Re: Q: list of lists

by Gavin LaRose -
Number of replies: 0
Hi Dick,

You can do the same sort of nested data in Perl and therefore in problems. The following should be something that would work.

@BX = ( [ 1, [2,4,5,8,11] ], [ 2, [2,3,4,5,8,11] ], [ 3, [3,4,8,11] ] );
$j = random( 0, scalar(@BX), 1 );
$b = $BX[$j]->[0];
$x0 = $BX[$j]->[1];

Now $x0 is a list reference. Thus if $j is 0, @$x0 is the list (2,4,5,8,11) and we can dereference elements of the list with the arrow operator: $x0->[3] is 5.

Does that help?
Gavin