There are often occasions where i'd like to look up multiple county names from their ids at one time, so I allow the second param, county_id to be either a scalar (one county_id), or an arrayref of county_ids.
If called with one county id, it returns the name as a scalar, and if called with an arrayref, it returns a hashref where the keys are the county_id's and the values are the corresponding names.
This works fine, but I am determining the return context based on the input params, as opposed to using wantarray(). So this seems a bit paradoxical, because if i call the function with 1 county_id, I know I want 1 name back, and calling with multiple county_id's, I want multiple names back.
In any case, wantarray() wont tell me anything useful, becuase I'm returning either a string or a hashref, which get assigned to a scalar, so wantarray() will return defined but false in both cases if I call it with a proper return assignment:
So, is this type of call / return pairing a normal thing to do, or am I smoking crack today?my $name = county_name_by_id($dbh, 23); my $name_refs = county_name_by_id($dbh, [12, 25, 7, 13]);
In reply to function call / return philosophies by shemp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |