Is there any way to know if my sub was called in a "numerical" context or a "string" context?
A partial solution is to use dualvar from Scalar::Util but then I have to compute both the string and the number on each call.use strict; sub sensible { return "one" if stringcontext(); return 1 if numericalcontext(); return; } print "Result = ".sensible()."\n"; # Result = one print "Result = ".0+sensible()."\n"; # Result = 1
Many thanks
Casiano
In reply to Finding the context of a call: numerical or string by casiano
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |