Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What’s the best way to shuffle an array in Perl?

So I have a file. Let’s say it looks like this (it's actually longer):

1234
2134
3124
4123

What is the best way to shuffle the lines in that file?

like image 687
Bill Avatar asked Nov 16 '12 12:11

Bill


1 Answers

#!/usr/bin/env perl

use strict;
use warnings;

use List::Util qw/shuffle/;

my @arr = shuffle <>;

print @arr;

Usage :

./script file.txt
like image 105
Gilles Quenot Avatar answered Nov 19 '22 20:11

Gilles Quenot