in reply to Re: Re: Re: Dereference an array reference
in thread Dereference an array reference
[methods (and subs in general)]
can return lists in a list context,
or scalars in a scalar context. Nothing else.
Cannot return an array.
Okay, merlyn. I'm puzzled again. If anyone else had posted this assertion, I would have made this as a correction rather than a genuine inquiry. The following snippet seems to demonstrate the ret_array sub returning an array. But I've been enough rounds on the array/list thing to know that things ain't always what they seem. Is more happening here than meets the eye?
sub ret_array { return @_; } sub ret_list { return @_[0..$#_]; } my @array = ('a','b','c'); print scalar ret_array('a','b','c'); # 3 print scalar ret_array(@array); # 3 print scalar ret_list('a','b','c'); # c print scalar ret_list(@array); # c
|
---|
Replies are listed 'Best First'. | |
---|---|
(tye)Re: Sub cannot return an array?
by tye (Sage) on Apr 20, 2001 at 01:00 UTC | |
by dvergin (Monsignor) on Apr 20, 2001 at 01:08 UTC | |
by tye (Sage) on Apr 20, 2001 at 01:16 UTC | |
Re: Sub cannot return an array?
by merlyn (Sage) on Apr 20, 2001 at 01:03 UTC | |
by dvergin (Monsignor) on Apr 20, 2001 at 01:25 UTC | |
by tye (Sage) on Apr 20, 2001 at 01:32 UTC |
In Section
Seekers of Perl Wisdom