Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: $! context behavior

by miyagawa (Chaplain)
on Aug 01, 2001 at 13:51 UTC ( #101337=note: print w/replies, xml ) Need Help??


in reply to $! context behavior

use overload. Here is a class that returns "foo" in a string context, and retutns 1 in numeric context.

package SampleOverload; use overload '""' => \&as_string; use overload '0+' => \&as_num; sub new { bless { str => "foo", num => 1 }, shift; } sub as_string { shift()->{str}; } sub as_num { shift()->{num}; }

Interesting examples of modules using overload is y2k and Dunce::time, that magically fixes y2k or 10-digit time problem.

--
Tatsuhiko Miyagawa
miyagawa@cpan.org

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-05-19 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (72 votes). Check out past polls.

    Notices?