Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: How do I write subs that take bare blocks as args?

by educated_foo (Vicar)
on Jun 28, 2002 at 06:33 UTC ( #177948=note: print w/replies, xml ) Need Help??


in reply to Re: How do I write subs that take bare blocks as args?
in thread How do I write subs that take bare blocks as args?

..which also worked. Is there any advantage/disadvantage to this over eval?
The eval version probably isn't doing what you want, unless you are doing something deliciously perverse. I think your original code is doing this:
# "$x = eval &$foo" becomes: my $tmp = &$foo(@_); $x = eval $tmp;
So you're passing @_ to the user's block, then eval'ing the result. This ends up working because the block presumably accesses $_ directly, and returns an integer (which evals as itself). But it's an ... interesting way to get the job done. An optimist would say that the eval version is "very general".

/s