This solution strikes me as rather elegant, but somewhat inefficient, but I can live with that since I need to eval this only once. Now, my main concern is how I would set individual elements (through a call to another method).

I could only think of the same approach: Create a sub on the fly that can be called with the proper arguments. Something like:

Ahh .. that looks good. Thanks. From past experience, I tend to avoid recursion as much as possible since it is usually slower than the more direct approach. I guess that in this case, recursion is the most natural representation. I'll try to benchmark it and see.

When dealing with trees, it's hard to avoid recursion. And this really is a tree problem: Create a structure which has i0 children, each of which have i1 children, .., each of which has 'i(n-1)' children.

Normally, recursion can be avoided with AoA(oA(oA))) by hardcoding the for loops, because the list of loop counter vars acts as the stack recursion would give us. This doesn't apply in this case, because we have an arbitrary number of for loops.

You could avoid recursion in this case by creating an 1-dimentional array of loop counters as long as the input list, but it would overcomplicate the code for nothing. It would be fun to code it for hte challenge, but I'm late.

You can can accomplish that for-loop without eval using NestedLoops from tye's Algorithm::Loops. And instead of eval'ing that anonymous sub to only work with a set number of indices, you can use a function that takes an arbitrary list of indices to dereference (which answers your main question).

Inside the map block is what happens in your deepest loop level. That is a reference to an array of $size[2] zeros. The list map acts on is bogus. Any list of $size[1] items would do there because the data in that list is never touched or remembered. It's only there to make $size[1] different copies of the inner array. A reference is taken to the whole map expression to make the top level data in @array.

Here's a solution with neither eval nor recursion. In terms of efficiency, for a total of N elements created, this requires between 1N and 1.5N passes (best & worst cases I got with a fair number of tests).