Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Creating Symmetrical AoA from some Arrays

by pg (Canon)
on Nov 25, 2005 at 04:47 UTC ( #511587=note: print w/ replies, xml ) Need Help??

in reply to Creating Symmetrical AoA from some Arrays

Or you can make it more generic with recursive code:

use Data::Dumper; use strict; use warnings; my $arr1 = ['A', 'B', 'C']; my $arr2 = ['foo', 'bar', 'qux']; my $arr3 = [1, 2, 3]; my $arr4 = ['apple', 'banana', 'pear']; print Dumper(mix($arr1, $arr2, $arr3, $arr4)); sub mix { if (@_ > 2) { return mix($_[0], mix(@_[1..$#_])); } else { my @a = map {[$_[0]->[$_], (ref($_[1]->[0]) eq 'ARRAY') ? @{$_ +[1]->[$_]} : $_[1]->[$_]]} (0 .. @{$_[0]} - 1); return \@a; } }

Which prints:

$VAR1 = [ [ 'A', 'foo', 1, 'apple' ], [ 'B', 'bar', 2, 'banana' ], [ 'C', 'qux', 3, 'pear' ] ];

Comment on Re: Creating Symmetrical AoA from some Arrays
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://511587]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (15)
As of 2015-11-30 20:20 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (781 votes), past polls