Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by kvale (Monsignor)
on Jun 28, 2002 at 06:02 UTC ( #177943=note: print w/replies, xml ) Need Help??


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

Use a prototype. Here is an example from Graham Barr's List::Util:
sub first (&@) { my $code = shift; foreach (@_) { return $_ if &{$code}(); } undef; }
which is invoked as
# first defined value in @list $foo = first { defined($_) } @list;
-Mark

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://177943]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2017-11-18 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?