用perl语言,实现以下结果,若一个文件有n行,随机抽取其中n行。。。

用perl语言,实现以下结果,若一个文件有n行,随机抽取其中n行。。。,第1张

#!c:/Perl/bin/perl.exe

print "Content-type: text/html\n\n"

open(destfile,"c:/menu.lst")

while(<destfile>)

{

$n=$n+1

}

$N=int(rand($n))

close(destfile)

print "<html><h1>总行数$n行 <br>随机取$N行</h1></html>\n"

#读取文件行数n,设定$N<$n,随机取小于n的整数N.

open(destfile,"c:/menu.lst")

while(<destfile>)

{

$c=$c+1

print $_ if ($c==$N)

}

close(destfile)

windows下随便写的,版本perl 5.10.1

1、获取目录下所有文件名

my $dir = '你的目录'

opendir( DIRHANDLE, "$dir" ) or die "can not open dir"

my @allfile = readdir(DIRHANDLE)

closedir (DIRHANDLE)

2、改名字

foreach $old (@allfile){

rename("$dir/$old","$dir/$new")

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8103937.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存