在Perl中对数组进行洗牌的最佳方法是什么?

时间:2022-11-24 16:14:30

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 个解决方案

#1


24  

#!/usr/bin/env perl

use strict;
use warnings;

use List::Util qw/shuffle/;

my @arr = shuffle <>;

print @arr;

Usage :

用法:

./script file.txt

#1


24  

#!/usr/bin/env perl

use strict;
use warnings;

use List::Util qw/shuffle/;

my @arr = shuffle <>;

print @arr;

Usage :

用法:

./script file.txt