Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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...

In reply to Re: Prototypes allow overloading subs? by dbp
in thread Prototypes allow overloading subs? by BUU

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2022-05-16 08:02 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (62 votes). Check out past polls.