Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there anyway to make your own function that can take a block of code (without the "sub" keyword) like those functions can or are they super magical?
  • Comment on How do I pass a block like map/grep/sort/etc?

Replies are listed 'Best First'.
Re: How do I pass a block like map/grep/sort/etc?
by revdiablo (Prior) on Mar 06, 2004 at 02:17 UTC
    Is there anyway to make your own function that can take a block of code

    In short, yes. perldoc perlsub, read about prototypes.

      Sweet, I didn't know about '&', I couldn't find it when I was looking for prototypes earlier. How do these functions get away with being unprototyped though (i.e. print prototype "grep"; prints nothing).

        Quoth perldoc -f prototype:

        If the builtin is not overridable (such as "qw//") or its arguments cannot be expressed by a prototype (such as "system") returns "undef" because the builtin does not really behave like a Perl function.
        err I mean "CORE::grep".