Have you ever thought about returning neither but something else instead?
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...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.