shemp has asked for the wisdom of the Perl Monks concerning the following question:
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]);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: function call / return philosophies
by Eimi Metamorphoumai (Deacon) on Sep 03, 2004 at 18:56 UTC | |
Re: function call / return philosophies
by ehdonhon (Curate) on Sep 03, 2004 at 19:03 UTC | |
Re: function call / return philosophies
by ikegami (Patriarch) on Sep 03, 2004 at 18:59 UTC | |
Re: function call / return philosophies
by ccn (Vicar) on Sep 03, 2004 at 19:56 UTC | |
Re: function call / return philosophies
by acomjean (Sexton) on Sep 03, 2004 at 20:17 UTC | |
Re: function call / return philosophies
by ihb (Deacon) on Sep 03, 2004 at 21:31 UTC |