English 中文(简体)
我怎么能够把佩雷尔的物体归为整个阵列,而不仅仅是其长度?
原标题:How can I force an object attribute in Perl to be set to a full array instead of just its length?
  • 时间:2011-03-10 15:28:06
  •  标签:
  • perl

I have an object I defined with a method, childNodes(), which returns an array. When I do something like:

my @arr = obj->childNodes()

I can clearly see that it can properly return an array.

My problem is that when I try to use this method to set the attribute of another class object, Perl decides I just want the length of childNodes() rather than the full array. This is not at all what I want and ruins everything. The code I m using for this is:

$self->{ _arr } = obj->childNodes()

How can I make this set $self->{ _arr } to an array instead of just a scalar number?

提前感谢!

最佳回答

当你评估一个阵列时,它会恢复阵列的长度。

你们想提及阵列:

$self->{ _arr } = [ obj->childNodes() ];

perldoc perlref

问题回答

暂无回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签