在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;
用法:
./script file.txt