in reply to Finding the context of a call: numerical or string
Or you can create a dualvar using dualvar in core module Scalar::Util. Then, the returned value with be *both* a string and a number.
use Scalar::Util qw( dualvar ); sub sensible { return dualvar(1, "one"); } my $foo = sensible(); print "Result = ", ''.$foo, "\n"; # Result = one print "Result = ", 0+$foo, "\n"; # Result = 1
Very fast too. Nothing special as far as Perl is concerned.
|
|---|