Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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


Comment on Re: Re: How do I write subs that take bare blocks as args?
Download Code

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 web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2014-09-19 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (137 votes), past polls