首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

如何把read 文件这部分 作为一个子函数呢

2012-06-09 
怎么把read 文件这部分作为一个子函数呢Perl code#!usr/bin/perlmy $file$file s.txtsub read{my $c

怎么把read 文件这部分 作为一个子函数呢

Perl code
#!usr/bin/perlmy $file;$file = "s.txt";sub read{    my $content = <@_>;    return $content;}open(FILE,"<$file") or die "can not open $file";read(FILE);close(FILE);

错误消息:
Not enough arguments for read at k1.pl line 15, near "FILE)"

怎么把read 文件这部分 作为一个子函数呢 


[解决办法]
那是因为 read 是 perl 的保留关键字,不能用作他用。

你可以:
my $txt = &read(FILE);
或者换个名字,别与保留关键字冲突

热点排行