in reply to Return a Reference or Array?
I could imagine that you do pretty much the same things with all the arrays you return from your various subs (checking their sizes, iterating over them etc).
So why not wrap your arrays in an object that provides nice convenience methods, iterators etc do make life easy for the client code?
In that way you ALWAYS return the same entity (an object - contextual returns are nice but can be confusing to some people) regardless of the list-size (with the memory consumtion of a returned reference), so no special cases and you could build an interface like this:
my $ret = &my_sub(@args); # returns an object that wraps a list if(! $ret->isEmtpy ) { $ret->each( sub { print $_ } ); }
Just an idea...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Return a Reference or Array?
by moritz (Cardinal) on Apr 06, 2009 at 22:07 UTC | |
by morgon (Priest) on Apr 06, 2009 at 22:33 UTC | |
by CountZero (Bishop) on Apr 06, 2009 at 22:41 UTC | |
by morgon (Priest) on Apr 06, 2009 at 22:48 UTC | |
by chromatic (Archbishop) on Apr 07, 2009 at 00:01 UTC |