【发布时间】:2011-07-28 23:05:10
【问题描述】:
我有一个 Perl 类文件(包):person.pl
package person;
sub create {
my $this = {
name => undef,
email => undef
}
bless $this;
return $this;
}
1;
我需要在另一个文件中使用这个类:test.pl
(注意person.pl和test.pl在同一个目录)
require "person.pl";
$john_doe = person::create();
$john_doe->{name} = "John Doe";
$john_doe->{email} = "johndoe@example.com";
但它没有成功。
我正在使用 XAMPP 来运行 PHP 和 Perl。
我认为使用“require”来获取似乎不太合适 “人”类的代码,但我不知道 如何解决这个问题。请帮忙...
【问题讨论】:
-
你好 nicola,欢迎来到 Stack Overflow。请花一些时间熟悉editing help 关于代码格式的内容。
-
您应该以大写字母开头所有包的名称。 Perl 的约定是模块以大写字母开头,语用符号全部小写以一目了然。
-
@shawn:人们喜欢这种约定,但是,我经常做相反的方式。 my_class_name 和 My_Instance_Name。我的约定来自自然的人类语言,比如“software_engineer”是类名,“John Smith”是一个“software_engineer”,看起来更自然。我通常在我的项目中使用这个约定。有点奇怪。 :D
标签: perl oop class include require