简体   繁体   English

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

[英]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? 在该文件中改变行的最佳方法是什么?

#!/usr/bin/env perl

use strict;
use warnings;

use List::Util qw/shuffle/;

my @arr = shuffle <>;

print @arr;

Usage : 用法:

./script file.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM