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}); } }

In reply to Re^2: Randomize elements among several arrays, while maintaining original array sizes. by EvanK
in thread Randomize elements among several arrays, while maintaining original array sizes. by BioNrd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.