LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 992|回复: 4

大家看看这个perl的自定义函数问题

[复制链接]
发表于 2004-8-24 23:08:40 | 显示全部楼层 |阅读模式
我写的程序如下:
#!/usr/bin/perl

print max(45..121,12..23)."\n";
print max(23..34,356..564)."\n";
        sub max{
        my($max)=shift(@_);
        foreach $temp (@_){
                if $temp > $max
                        $max=$temp;
                }
        return($max);
}

运行时提示出错,我检查了好几遍,实在查不出那里出错了
提示如下:

Scalar found where operator expected at print.pl line 9, near "$max
                        $max"
        (Missing operator before $max?)
syntax error at print.pl line 8, near "if $temp "
Execution of print.pl aborted due to compilation errors.


大家帮看看那里错了
谢谢
发表于 2004-8-25 16:16:32 | 显示全部楼层
if $temp > $max
$max=$temp;
問題就在這兒
 楼主| 发表于 2004-8-25 22:02:36 | 显示全部楼层
这句怎麽错了
请明示!
谢谢!
发表于 2004-8-25 22:55:52 | 显示全部楼层
 楼主| 发表于 2004-8-25 23:06:53 | 显示全部楼层
谢谢斑竹
那个有本书上说 不加括弧也行的
是不是Perl版本的问题呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表