Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Creating Symmetrical AoA from some Arrays

by pg (Canon)
on Nov 25, 2005 at 04:47 UTC ( [id://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' ] ];

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found