in reply to User variables with two values?

For a lighter solution, just use a (built-in) dualvar:

use Scalar::Util 'dualvar'; my $funny = dualvar 12, 'pancake'; printf "Polly wanna %s every %d days \n", $funny, $funny; printf "Polly wanna %s every %d days \n", $funny, 0+$funny; __END__
Or, if you really do want a full object-based solution, Contextual::Return can do the hard work (of setting up the class and overloading) for you:
use Contextual::Return; my $funny = NUM { 12 } STR { 'pancake' }; printf "Polly wanna %s every %d days \n", $funny, $funny; printf "Polly wanna %s every %d days \n", $funny, 0+$funny; __END__
But, if you just want number and string, a dualvar is probably the better choice.


Comment on Re: User variables with two values?
Select or Download Code