孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

2011年4月27日

摘要: #!/usr/bin/perl # use threads; sub say_hello { printf("Hello thread! @_.\n"); sleep(10); printf("Bye\n"); } 阅读全文
posted @ 2011-04-27 23:05 孤独的猫 阅读(133) 评论(0) 推荐(0)

摘要: 注意在perl5.8中,必须用threads->create来生成线程,和许多介绍旧版perl的书籍中的有区别 use Thread qw/async yield/; my $done=0; sub frob { my $arg=shift; my $tid=Thread->self->tid; print "thread $tid:frob $arg\n"; yield; unless ($done) { yield; $done++; frob($arg+10); } } 阅读全文
posted @ 2011-04-27 23:01 孤独的猫 阅读(305) 评论(0) 推荐(0)

摘要: 打开、关闭文件 open (filevar, filename) filevar为文件句柄,或者说是程序中用来代表某文件的代号 filename为文件名,其路径可为相对路径,亦可为绝对路径 open(FILE1,"file1"); open(FILE1, "/u/jqpublic/file1"); 阅读全文
posted @ 2011-04-27 22:01 孤独的猫 阅读(423) 评论(0) 推荐(0)

摘要: foreach my $person(qw /fred wilma betty barney dino perbbles /) { eval { open FILE, "$person" or die "Can't open file '$person': $!'"; 阅读全文
posted @ 2011-04-27 21:53 孤独的猫 阅读(263) 评论(0) 推荐(0)

摘要: 多线程编程需要引用threading包 阅读全文
posted @ 2011-04-27 20:46 孤独的猫 阅读(307) 评论(0) 推荐(0)