How do I shuffle two arrays in exactly the same way in Perl?

arrays, perl, shuffle

Solution

Try (something like) this:

use List::Util qw(shuffle);
my @list1 = qw(a b c d e);
my @list2 = qw(f g h i j);
my @order = shuffle 0..$#list1;
print @list1[@order];
print @list2[@order];

Problem

Does anyone know how to shuffle two arrays randomly in exactly the same way in Perl? For example, say I have these two arrays: Before shuffling: array 1: 1, 2, 3, 4, 5 array 2: a, b, c, d, e After shuffling: array 1: 2, 4, 5, 3, 1 array 2: b, d, e, c, a So every element in each array is bound to its equivalent element.

Original source