Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: User variables with two values?

by Anonymous Monk
on Aug 19, 2012 at 21:33 UTC ( #988362=note: print w/ replies, xml ) Need Help??

in reply to User variables with two values?

See overload, Polly wanna pancakes every 12 days

#!/usr/bin/perl -- use strict; use warnings; my $funny = NumStr->new( num => 12, str => "pancakes" ); printf "Polly wanna %s every %d days \n", $funny, $funny; printf "Polly wanna %s every %d days \n", $funny, 0+$funny; BEGIN { package NumStr;{ use overload "0+" => \# use overload '""' => \&str; use overload "fallback" => 1; sub new { my $class = shift; bless { @_ }, $class; } sub num { return shift->{num}; } sub str { return shift->{str}; } $INC{''}=__FILE__; } }

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988362]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2015-09-03 18:35 GMT
Find Nodes?
    Voting Booth?

    My preferred temperature scale is:

    Results (123 votes), past polls