Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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__; } }

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 browsing the Monastery: (13)
As of 2016-10-25 18:08 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (326 votes). Check out past polls.