Chinaunix

标题: perl OOP [打印本页]

作者: wangsheng0415    时间: 2008-07-12 20:43
标题: perl OOP
第一次接触perl OOP,在网上找了个程序,执行时出错,
程序有两个类Base.pm,Derive.pm,

错误信息:cann't locate object method "new" via package "Base" at Derive.pm line 15.
line 15 at Derive.pm部分程序为:
sub new{

  my $type=shift;

  my $this=Base->new();

  $this->{'Derive'}='instant';

  bless $this,$type;

  return $this;

}

测试程序test.pl为
push(@INC,`pwd`);

use Derive;

$cup=new Derive;

print $cup->{'Derive'};

print "\n";

print $cup->{'Base'};

print "\n";

$cup->setBaseType('Mixed');

$cup->setDeriveType('mmmm');
<>

请大侠指点下!!!!!!!
作者: flw    时间: 2008-07-12 22:50
第一次接触就不从教程开始而是从网上的例子开始,
难道语法都是“试出来”的吗?

perldoc perltoot
perldoc perlboot
perldoc perlobj
perldoc perltooc
作者: wangsheng0415    时间: 2008-07-12 23:04
看了Perl入门,小骆驼的,但里面没有讲OOP
作者: wangsheng0415    时间: 2008-07-12 23:08
谢谢flw,我看看perldoc先......
作者: churchmice    时间: 2008-07-12 23:27

  1. BEGIN {
  2. push(@INC,`pwd`);
  3. }
复制代码

作者: flw    时间: 2008-07-12 23:28
小骆驼没有就看大骆驼。
你也知道小骆驼的名字其实是叫《Perl 入门》的。
作者: wangsheng0415    时间: 2008-07-12 23:30
哪个大骆驼?
有本书是:可以解决难题的Perl脚本...难
请推荐一本
作者: wangsheng0415    时间: 2008-07-12 23:35
5楼的加上了还不行啊
作者: wangsheng0415    时间: 2008-07-14 21:30
不知道为什么这样就行了
BEGIN{
unshift @INC,"../OOP";#OOP是文件夹
}
不能用pwd来代替"../OOP",我是在windows下的....
unshift也不能改成push




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2