Pathologically Eclectic Rubbish Lister | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Assuming @one and @two have the same number of elements and that you wanted each element to be an arrayref...
Or
It would also be possible to create a tied array that looks up its values in the other arrays in real time, but that would be more complicated and probably has no advantage, unless you want changes to the original arrays to be reflected in the multidimensional one. update: fixed subscripting fencepost error pointed out to me by revdiablo and L~R. And yes, if the arrays might not be the same length you can check which one is longer and use either the shorter or the longer one to determine the upper bound of the range operator, depending on which results you want (whether you want the arrayrefs that would have an undef element or not). But I got the impression from the question that they would necessarily be the same length. Since nobody else has done so, I will also point out that the syntax the OP used for the desired structure is wrong. He has this (which of course is a syntax error):
It appears that what he wanted is this:
Though I personally would have used the funny comma (=>) within each of those arrayrefs especially if there are exactly two elements in each. But that doesn't technically matter, I think.
In reply to Re: build multidimensional array from arrays
by jonadab
|
|