in reply to Code references as use() parameters

Wouldn't a simple pre-declaration in a BEGIN block solve the problem?

You could even put this with or inside the subroutine body to keep things together.

#! perl -slw use Try qw[ \&callback ]; sub callback{ BEGIN{ sub callback; } #do stuff }

Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

Replies are listed 'Best First'.
Re: Re: Code references as use() parameters
by broquaint (Abbot) on Apr 09, 2003 at 17:00 UTC
    Wouldn't a simple pre-declaration in a BEGIN block solve the problem?
    Nope as the sub still has to be parsed e.g
    BEGIN { foo(); } sub foo { BEGIN { sub foo } print "in foo()"; } __output__ Undefined subroutine &main::foo called at 249927.pl line 2. BEGIN failed--compilation aborted at 249927.pl line 3.
    So you need to delay the execution of the coderef until after compile-time unless you can force the compilation of the given sub.
    HTH

    _________
    broquaint

      Right. I brainfarted again.


      Examine what is said, not who speaks.
      1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
      2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
      3) Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke.