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

2020-08-09 10:26发布

问题:

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?

回答1:

#!/usr/bin/env perl

use strict;
use warnings;

use List::Util qw/shuffle/;

my @arr = shuffle <>;

print @arr;

Usage :

./script file.txt