in reply to Randomize elements among several arrays, while maintaining original array sizes.

Learn some basic perl man!!
@b = ( @a, 11, 32 ); my ( @newa, @newb, @newc ); my @sizes = ( scalar(@a), scalar(@b), scalar(@c) ); my @where_to = qw/a b c/;
I'm still not sure what you're trying to do.. but you might want to checkout perldoc -q shuffle
use List::Util 'shuffle'; @shuffled = shuffle(@list);
UPDATE I believe the op just now clarified what about something like this, using parallel assignment:
use XXX; use List::Util; @a=qw/foo bar baz/; @b=qw/mickey/; @c=qw/x y z/; (@a[0..$#a],@b[0..$#b],@c[0..$#c]) = List::Util::shuffle(@a,@b,@c); XXX [\@a, \@b, \@c]'


Evan Carroll
I hack for the ladies.
www.EvanCarroll.com

Replies are listed 'Best First'.
Re^2: Randomize elements among several arrays, while maintaining original array sizes.
by EvanK (Chaplain) on Aug 01, 2008 at 16:40 UTC
    Presumably, his example a, b, and c arrays are datasets from some outside source, so your a+b suggestion likely doesn't add anything. Additionally, I don't even know what you meant to do with @where_to, as you're just assigning strings 'a', 'b' and 'c'.

    The simplest way to do what the OP wanted would be as pjotrik suggested. Your recommendation of List::Util's shuffle is definitely a good suggestion though.

    Addendum: A quick and dirty example...

    #!/usr/bin/perl -w use strict; use List::Util 'shuffle'; my @array_a = (10, 22, 34, 21, 20, 12, 32, 31, 91, 20); my @array_b = (10, 22, 34, 21, 20, 12, 32, 31, 91, 20, 11, 32, 44, 51, + 10, 22, 82, 71, 61, 54); my @array_c = (14, 25, 64, 71, 80); mass_shuffle(\@array_a, \@array_b, \@array_c); sub mass_shuffle { # all sub-arrays passed by ref my @arrays = @_; # combine into one large array and shuffle it my @shuffler; foreach my $sub (@arrays) { push @shuffler, @{$sub}; } @shuffler = shuffle(@shuffler); # splice properly sized randomized replacements foreach my $sub (@arrays) { @{$sub} = splice @shuffler, 0, scalar(@{$sub}); } }
      The @where_to, is a list of places where the items are destined to go. I want to not simply shuffle the arrays. That is easy as has been pointed out, and I am aware of how to do this (having learned "some basic perl").

      I want to move the items around between the arrays, while maintaining the array sizes. So items in A can move to A, B, or C.

      It is not so much shuffling the order of each array as it is shuffling where each elements goes and creating new arrays of size A B and C that now have elements drawn from A B or C. In essence, I am trying to set up a permutation test, but having great difficulty with this.

      ---- Even a blind squirrel finds a nut sometimes.