in reply to Passing subroutines as arguments

But I can't figure out how to use a subroutine once I pass it to another subroutine.

Assuming that you have a reference to a subroutine in $sub,

&$sub(); or $sub->();
will invoke that subroutine without arguments, and
&$sub(1, 2, "grapefruit"); or $sub->(1, 2, "grapefruit");
will invoke it with arguments.

Which form you choose is a matter of style.

Replies are listed 'Best First'.
Re: Re: Passing subroutines as arguments
by dragonchild (Archbishop) on May 08, 2003 at 19:53 UTC
    Which form you choose is a matter of style. Uhh - not quite. &FOO and FOO() do different things with @_ and barewords. While the latter isn't a concern here, the former might be. YMMV.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      Uhh - not quite. &FOO and FOO() do different things with @_ and barewords.

      Noting that &FOO and FOO() behave differently is fine, but please don't use the pretense of objecting to something that I didn't write. I didn't (and don't) recommend the &FOO form except under very contorted circumstances.

      In Response to dragonchild's post:
      I think in this instance you may have wanted to post how they behave differently, as the peson who posted the question is obviously not going to realize this difference.

      When one criticizes another's reply to a post, it is considered good manners to explain oneself fully instead of giving very terse comments. As this behaviour could be misconstrued to be argumentative and counterproductive.