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

Re: Overloading Subs in Perl

by cjf-II (Monk)
on Dec 04, 2002 at 06:02 UTC ( #217423=note: print w/replies, xml ) Need Help??


in reply to Prototypes allow overloading subs?

If you want clean function overloading in Perl take a look at Class::Multimethods.

There's also the appropriately named overload module, which I have yet to use but looks interesting.

Update: Here's an example with Class::Multimethods:

use Class::Multimethods; multimethod add => ('#', '#') => sub { $ans = $_[0] + $_[1]; print $ans, "\n" }; multimethod add => ('$', '$') => sub { $ans = $_[0] . $_[1]; print $ans, "\n" }; add(1, 2); add("Foo", "Bar");

Is this what you're thinking of?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2022-01-17 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (51 votes). Check out past polls.

    Notices?