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.
In reply to Auto-detecting returned or passed variable type by richard5mith
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |