http://qs1969.pair.com?node_id=73991


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