richard5mith has asked for the wisdom of the Perl Monks concerning the following question:
I have two functions, function A and function B.
The result of Function B is one of the parameters that is passed to function A. Function A then does something with this and returns the result.
The problem I have is that I'm not sure what Function B is going to return. It may return a scalar, it may return an array or it may return a hash. It may even be a reference to one of these.
Therefore, this makes it very difficult to code Function A when you're not sure what it's going to get. Obviously the correct way would be always to pass Function A a reference to whatever Function B returned, but how can I create the reference to it when I don't know what it's going to be?
Function A can easily detect references and scalars (if it only got one value), but if it gets more than one value, then it could either be an array or a hash, and I can't see how it could tell the difference unless it was a reference.
As an extra bonus, the call to Function A, with whatever is being passed to it (the result of Function B and whatever other parameters), must be a single line.
Challenge extended.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Auto-detecting returned or passed variable type
by merlyn (Sage) on Aug 19, 2004 at 19:52 UTC | |
by richard5mith (Beadle) on Aug 19, 2004 at 20:12 UTC | |
by merlyn (Sage) on Aug 19, 2004 at 21:01 UTC | |
by richard5mith (Beadle) on Aug 19, 2004 at 21:36 UTC | |
by merlyn (Sage) on Aug 19, 2004 at 21:41 UTC | |
|
Re: Auto-detecting returned or passed variable type
by VSarkiss (Monsignor) on Aug 19, 2004 at 20:10 UTC | |
by richard5mith (Beadle) on Aug 19, 2004 at 20:14 UTC | |
by roju (Friar) on Aug 19, 2004 at 21:14 UTC | |
|
Re: Auto-detecting returned or passed variable type
by ikegami (Patriarch) on Aug 19, 2004 at 21:49 UTC |