Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://177948]
help
Chatterbox?
and the voices are still...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2017-10-24 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (286 votes). Check out past polls.

    Notices?