WeBWorK Problems

using a list of lists

Re: using a list of lists

by Davide Cervone -
Number of replies: 0
You are welcome for MathObjects, I'm glad you are able to make use of them.

As for

    @DATA = ( (0,6) , (1,7) , (2,8) , (3,9) ) ;
you probably discovered that Perl "flattens" arrays of arrays, so this was effectively the same as
    @DATA = ( 0, 6, 1, 7, 2, 8, 3, 9 ) ;
so the array of references (using square brackets) is the only way to do what you want, here.

As for mapping compute over a list, you can use the MathObject List object to do that for you:

    ($art,$x0,$y1) = List(@{$DATA[$k]})->value;
This first creates a List out of the contents of the array pointed to by $DATA[$k}, which converts its entries into MathObjects automatically, and then "unpacks" the MathObject into a Perl list of its contents, which you then break up into the three variables on the left.

Or you could use Lists in your original DATA array:

    @DATA = ( List(0,6) , List(1,7) , List(2,8) , List(3,9) ) ;
    ($art,$x0,$y1) = $DATA[$k]->value;
As usual, there are several ways to do anything in Perl. :-) Davide