Mark Stosberg wrote:
On Tue, Mar 01, 2005 at 02:40:36PM -0800, Ofer Nave wrote:
# getting fancy with arg binding
my @hosts = qw( foo bar baz );
prun( map { my $host = $_; sub { test_host( $host ) } } @hosts )
or die( Parallel::Simple::errplus() );
I think this is simpler, because I can guess what it does without
reading more documentation.
My idea of simple here is clarifying the call some:
my @host_tests;
for qw( foo bar baz ) {
push @host_tests, sub { test_host( $_ ) };
}
prun (@host_tests) or die( Parallel::Simple::errplus() );
I don't think that's going to do what you expect. The values in $_ are
not going to be captured in the anonymous sub because $_ is a global
variable. That's why I created a new lexical variable to capture the
value on each loop inside the closure.
It's not clear your code refs would interact with arguments that may
already be passed into them, before they get to prun().
It's also not 'normal' to mix hash and list calling styles, or to use a
code ref for a hash key.
The mixed hash/list calling styles is a seperate discussion - that was
already part of the initial design, and not part of the topic of this
email, which is whether or not the args binding feature is an
appropriate addition for the module. Also, I'm not using code refs as
keys anywhere. Simply putting a code ref on the left side of a =>
operator won't stringify it.
In summary, I don't think the suggested addition would be 'simple'.
Ah, that's the real question! I'm still not convinced either way, but
I'm leaning towards including it.
-ofer