读书人

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

发布时间: 2012-06-09 17:16:42 作者: rapoo

怎么把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);
或者换个名字,别与保留关键字冲突

读书人网 >perl python

热点推荐