Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-09-02 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (22 votes), past polls