In the question ‘Is returning a whole array from a Perl subroutine inefficient’ two people recommend against optimizing if there is no need for it. As a general rule, optimizing can add complexity, and if it’s not needed, simple is better. But in this specific case, returning an array versus an array ref, I don’t see that there’s any added complexity, and I think consistency in the interface design would be more important. Consequently, I almost always do something like:
sub foo { my($result) = []; #....build up the result array ref $result; }
Is there a reason I should not do this, even for small results?
You shouldn’t return an array reference if it’s inconsistent with the rest of your interface. If everything else that you work with returns lists instead of references, don’t be the odd duck who causes other programmers to remember the exception.
Unless you have large lists, this is really a micro-optimization issue. You should be so lucky if this is the bottleneck in your program.
As far as complexity goes, the difference between a reference and a list is so far down on the complexity scale that you have bigger problems if your programmers are struggling with that. Complicated algorithms and workflows are complex, but this is just syntax.
Having said all of that, I tend to make everything return references and make interfaces consistent with that.