如何把read 文件这部分 作为一个子函数呢
怎么把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);
或者换个名字,别与保留关键字冲突