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...
-
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 How to display code and escape characters
are good places to start.
|