Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to make bi-modal variables like $! ?

by japhy (Canon)
on Jun 28, 2001 at 20:14 UTC ( #92346=note: print w/replies, xml ) Need Help??


in reply to How to make bi-modal variables like $! ?

You'll need to do some overloading.
package DualVar; use overload ( '""' => sub { $_[0][0] }, '0+' => sub { $_[0][1] }, fallback => 1, ); sub new { bless [ @_[1,2] ], $_[0] } 1;
And that's all!
use DualVar; my $x = DualVar->new("japhy", 19); printf "I'm %s, and I'm %d years old.\n", $x, $x;


japhy -- Perl and Regex Hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://92346]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-06-26 14:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (583 votes). Check out past polls.