Chinaunix首页 | 论坛 | 博客
  • 博客访问: 402021
  • 博文数量: 20
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 1270
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-16 09:18
文章分类
文章存档

2011年(6)

2010年(2)

2009年(1)

2008年(11)

我的朋友

分类:

2008-04-19 11:09:42

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);

阅读(1158) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~