免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2986 | 回复: 1
打印 上一主题 下一主题

使用open 和 IO::file ?? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-09-19 13:47 |只看该作者 |倒序浏览
使用
$OFile = IO::File->;new("TITLE.dat";


open($OFile,"TITLE.dat";


请教 ->; 这俩种方法有什么不同???

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2003-09-19 14:25 |只看该作者

使用open 和 IO::file ??


  1. IO::File.pm
  2. =============================
  3. sub new {
  4.     my $type = shift;
  5.     my $class = ref($type) || $type || "IO::File";
  6.     @_ >;= 0 && @_ <= 3
  7. or croak "usage: new $class [FILENAME [,MODE [,PERMS]]]";
  8.     my $fh = $class->;SUPER::new();
  9.     if (@_) {
  10. $fh->;open(@_)
  11. or return undef;
  12.     }
  13.     $fh;
  14. }

  15. sub open {
  16.     @_ >;= 2 && @_ <= 4 or croak 'usage: $fh->;open(FILENAME [,MODE [,PERMS]])';
  17.     my ($fh, $file) = @_;
  18.     if (@_ >; 2) {
  19.         my ($mode, $perms) = @_[2, 3];
  20.         if ($mode =~ /^\d+$/) {
  21.             defined $perms or $perms = 0666;
  22.             return sysopen($fh, $file, $mode, $perms);
  23.         }
  24.         if (! File::Spec->;file_name_is_absolute($file)) {
  25.             $file = File::Spec->;catfile(File::Spec->;curdir(),$file);
  26.         }
  27.         $file = IO::Handle::_open_mode_string($mode) . " $file\0";
  28.     }
  29.     open($fh, $file);
  30. }

复制代码
   
看代碼會比較清楚...
IO::File->;new會call IO::File->;open 然後call open...
IO::File是比較OO的寫法....當然,如果我們不管OO..
直接調用open()會比較快...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP