Re: Can overloaded '+' return an array? If so, how?
- From: "jl_post@xxxxxxxxxxx" <jl_post@xxxxxxxxxxx>
- Date: 30 Aug 2006 13:40:56 -0700
PeterSShenkin wrote:
The issue is that "combine", which is the function that '+' maps to,
returns an array. When, in the main program, I say:
my @ar = $ca1 + ca2
I expect the "combine" function to be called in list context. But
evidently it is called in scalar context, because my @ar variable
receives the cardinality of the "result" array, rather than a copy of
the array.
...
(If, instead of what I do in the example, I return a reference to the
array, and alter my main routine correspondingly, then, of course,
everything works.)
I fiddled around with your test code, and I found that, while the
code:
my @ar = $ca1 + ca2;
is not called in list context, the following three functionally
equivalent lines:
my @ar = $ca1->combine($ca2);
my @ar = combine $ca1 $ca2;
my @ar = ClassAct::combine($ca1, $ca2);
do return an array as you want -- without the need to change the
combine() method.
(I don't know if this information is useful to you or not, but I
thought I'd share it anyway).
-- Jean-Luc
--
perl -le "print(pack'B*','0'.unpack'B*',pack'w*',
5592691776,37562575106519616,25926642752,354130435682904)"
.
- Follow-Ups:
- Re: Can overloaded '+' return an array? If so, how?
- From: PeterSShenkin
- Re: Can overloaded '+' return an array? If so, how?
- References:
- Can overloaded '+' return an array? If so, how?
- From: PeterSShenkin
- Can overloaded '+' return an array? If so, how?
- Prev by Date: Re: A Sort Optimization Technique: decorate-sort-dedecorate
- Next by Date: Re: Beginner: read $array with line breaks line by line
- Previous by thread: Re: Can overloaded '+' return an array? If so, how?
- Next by thread: Re: Can overloaded '+' return an array? If so, how?
- Index(es):
Relevant Pages
|
|