in reply to returning ref to static var vs. copying

uppose you have a subroutine which returns an array ref. There are basically two ways to do it:

Theres another way. Instead of making an @array, always use an array ref:

sub third_way { my $array_ref = []; ... add elements to $array_ref... $array_ref; }

regards,

Replies are listed 'Best First'.
Re^2: returning ref to static var vs. copying
by ikegami (Patriarch) on Jun 11, 2009 at 06:39 UTC
    It does have the advantage of consistency: The array is accessed by reference both in and out of the function.