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

Re: Prototypes allow overloading subs?

by dbp (Pilgrim)
on Dec 04, 2002 at 10:01 UTC ( [id://217446]=note: print w/replies, xml ) Need Help??


in reply to Prototypes allow overloading subs?

I've also had a need for this sort of functionality although not necessarily in an OO context. For example, say you want a sub to be called in a manner similar to the built-in sort (most likely in a module). This example (toy) code throws an error:
#!/usr/bin/perl -w use strict; sub func (&@) { my $func = shift; foreach (@_) { $func->($_); } } sub func (@) { foreach (@_) { print $_; } } my @list = ('bob', 'sally', 'joe'); func { print "!!!$_\n"; } @list; func @list;
It would be quite nice to be able to do this sort of thing. If you didn't need the prototype to treat a block as a sub things would also work out. It is also easy to work around this issue by taking an explicit reference to a sub but the block is much more natural and provides subs that are similar in use to the built-in functions. Perhaps I am missing something obvious...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found