Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: $! context behavior

by miyagawa (Chaplain)
on Aug 01, 2001 at 13:51 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-23 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found