Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: User variables with two values?

by DamianConway (Beadle)
on Aug 19, 2012 at 21:55 UTC ( #988366=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988366]
Discipulus uh the link was for cmd.exe the bash one
[marioroy]: If yes, for redirection to work, one might do the following
[marioroy]: `bash -c "clang --version 2>/dev/null"`
[choroba]: Sane people don't use csh
[marioroy]: the 1>&2 will work, not shown
[marioroy]: sorry, did not know which if cmd.exe or unix (bash)
[choroba]: csh considered harmful
[erix]: no, I'm using bash :)
[marioroy]: :)
[marioroy]: I use the default and happens to be bash

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-03-23 08:24 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (284 votes). Check out past polls.