【发布时间】:2015-12-10 04:49:13
【问题描述】:
我很清楚有几个关于类似主题的问题,但我看不到如何将答案应用于我的问题:
我不明白的是,我在两个包中使用了相同的架构,而在第一个包中没问题......包“1”来自哪里?
这是运行良好的包:
package ObjA;
use warnings;
use strict;
use Data::Dumper;
use Carp;
use ObjB;
#CONSTRUCTOR AND INITIALISATION
sub new {
my $class = shift;
my $self = {@_};
bless($self,$class);
$self->language();
return $self;
}
sub load {
my $self = shift;
open (my $stream,"<",$self ->{name});
my @glob_xs=();
my $i = 0;
while (<$stream>){
$i += 1;
my @x = extract($stream,());
@glob_xs=(@glob_tokens,@x);
}
$self->tokens(\@glob_xs);
}
sub extract{
my ($stream,@x) = @_;
my $line = <$stream>;
chomp $line;
if ($line =~ /^\s*$/){
return @x;
}
print join("/",split("\t",$line));
my $b = ObjB::new(split("\t",$line));
push @x,$b->form;
extract_sentence($stream,@x);
}
# OBJECT ACCESSOR METHODS
sub language {$_[0]->{language}=$_[1] if defined $_[1] ; $_[0]->{language}}
1;
这是产生错误的原因:
package ObjB;
use warnings;
use strict;
use Data::Dumper;
use Carp;
# CONSTRUCTOR AND INITIALISATION
sub new {
my $class = shift;
my $self = {@_};
bless($self,$class);
$self->idx(); # Dies here.
return $self;
}
# OBJECT ACCESSOR METHODS
sub idx {$_[0]->{idx}=$_[1] if defined $_[1] ; $_[0]->{idx}}
1;
会不会是因为 ObjB 在 ObjA 内部被调用?还是因为它们是在两个不同的文件中声明的?
我真的希望有人能给出答案,因为我一直在兜圈子......
谢谢!!
【问题讨论】:
-
ObjB::new看起来很可疑
标签: perl