Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Prototypes allow overloading subs?

by dbp (Pilgrim)
on Dec 04, 2002 at 10:01 UTC ( #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? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-01-22 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (59 votes). Check out past polls.

    Notices?