Perl Sleep时间

liujunyu 2010-10-28 05:52:37
请问perl中可以让程序sleep 500毫秒吗?
我在脚本中写:
map {
sleep(0.5);
} 1 .. 100;

我想让它sleep 0.5s,共100次,就是总共sleep 50秒,
但是程序是一瞬间就执行完了,sleep(0.5)不能达到效果。
...全文
531 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fibbery 2010-10-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zuo_shen 的回复:]
ls的资料是哪里查的啊?
[/Quote]

perldoc -f sleep
codesnail 2010-10-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zuo_shen 的回复:]
ls的资料是哪里查的啊?
[/Quote]
perldoc
zuo_shen 2010-10-29
  • 打赏
  • 举报
回复
ls的资料是哪里查的啊?
fibbery 2010-10-28
  • 打赏
  • 举报
回复
sleep 需要整数类型的参数,所以,0.5就是0,所以,循环100次也没效果。
fibbery 2010-10-28
  • 打赏
  • 举报
回复
sleep EXPR
sleep Causes the script to sleep for (integer) EXPR seconds, or
forever if no argument is given. Returns the integer number of
seconds actually slept.

May be interrupted if the process receives a signal such as
"SIGALRM".

eval {
local $SIG{ALARM} = sub { die "Alarm!\n" };
sleep;
};
die $@ unless $@ eq "Alarm!\n";

You probably cannot mix "alarm" and "sleep" calls, because
"sleep" is often implemented using "alarm".

On some older systems, it may sleep up to a full second less
than what you requested, depending on how it counts seconds.
Most modern systems always sleep the full amount. They may
appear to sleep longer than that, however, because your process
might not be scheduled right away in a busy multitasking system.

For delays of finer granularity than one second, the Time::HiRes
module (from CPAN, and starting from Perl 5.8 part of the
standard distribution) provides usleep(). You may also use
Perl's four-argument version of select() leaving the first three
arguments undefined, or you might be able to use the "syscall"
interface to access setitimer(2) if your system supports it. See
perlfaq8 for details.

See also the POSIX module's "pause" function.
steptodream 2010-10-28
  • 打赏
  • 举报
回复
用select

把你sleep(0.5);
换成
select(undef,undef,undef,0.5);
perl函数手册英文版 Perl提供了可以直接调用的、数目众多的函数。可以对以下对象进行操作: 数组:chomp, join, keys, map, pop, push, reverse, shift, sort, splice, split, unshift, values 数据库:dbmclose, dbmopen 目录:chdir, closedir, mkdir, opendir, readdir, rewinddir, rmdir, seekdir, telldir 文件:binmode, chdir, chmod, chown, chroot, close, eof, fnctl, fileno, flock, getc, glob, ioctl, link, lstat, open, print, printf, read, readdir, readlink, rename, rmdir, seek, select, stat, symlink, sysopen, sysread, syswrite, tell, truncate, umask, unlink, utime, write 组:endgrent, getgrent, getgrgid, getgrname, getpgrp, setgrent, setpgrp Hash: delete, each, exists, keys, values 主机:endhostent, gethostbyaddr, gethostbyname, sethostent 输入:getc, read, sysread 处理器间通讯:msgctl, msgget, msgrcv, msgsnd, pipe, semctl, semget, semop, shmctl, shmget, hmread, shmwrite 数学:abs, atan2, cos, exp, hex, int, log, oct, rand, sin, sqrt, srand 消息队列:msgctl, msgget, msgrcv, msgsnd 其他:bless, defined, do, eval, formline, import, ref, scalar, syscall, tie, tied, undef, untie, wantarray 网络:endnetent, getnetbyaddr, getnetbyname, getnetent, setnetent 输出:die, print, printf, syswrite, warn, write 口令:endpwent, getpwent, getpwname, getpwuid, setpwent 进程:alarm, die, dump, exec, exit, fork, getlogin, getpgrp, getppid, getpriority, kill, setpriority, sleep, system, times, umask, wait, waitpid 协议:endprotent, getprotobyname, getprotobynumber, getprotoent, getservbyname, getservbyport, getservent, setprotoent 正则表达式:grep, pos, quotemeta, reset, split, study 范围:caller, local, my 服务:endservent, getservbyname, getservbyport, getservent, setservent 套节字:accept, bind, connect, gethostbyaddr, gethostbyname, gethostent, getpeername, getservbyname, getservbyport, getservent, getsockname, getsockopt, listen, recv, select, send, setsockopt, shutdown, socket, socketpair 字符串:chop, chr, crypt, hex, index, join, lc, lcfirst, length, oct, Ord, pack, q, qq, quotemeta, qw, qx, reverse, rindex, split, sprintf, substr, uc, ucfirst, unpack, vec 时间:gmtime, localtime, time UNIX: chmod, chown, chroot, dump, endgrent, endhostent, endnetent, endprotent, endpwent, endservent, fnctl, fork, getgrent, getgrgid, getgrname, gethostent, getlogin, getnetent, getpgrp, getppid, getpriority, getprotobyname, getprotobynumber, getprotoent, getpwent, getpwname, getpwuid, getservbyname, getservbyport, getservent, ioctl, link, lstat, readlink, select, setgrent, sethostent, setnetent, setpgrp, setpriority, setprotoent, setpwent, setservent, sleep, syscall, times, umask, wait, waitpid

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧