how to select a random line from a file? These days, i am doing some research about corpus linguistics and preparing for a experiment.
#!/usr/bin/perl -w
#
#Copyright (c) 2008-2009 Zhang Shunchang
#
use strict;
open(INPUT,")or die"$!\n";
my @array = <INPUT>;
my $index = rand @array;
my $line = $array[$index];
print int($index)."\t".$line."\n";
close(INPUT);
|
阅读(1199) | 评论(0) | 转发(0) |