in reply to Dynamic Code?

I'm not sure if this is what you're after, but I think what you need is called a closure..

sub func{ return sub { if($joe){somesub($arg1,$arg2);} } } $a=&func(); # do stuff.. # call the function &$a;
I didn't test this, just wrote it. See perlman:perlref for more.
//mikkoH

Replies are listed 'Best First'.
RE: Re: Dynamic Code?
by mikkoh (Beadle) on Aug 25, 2000 at 14:00 UTC
    Dang, too little coffee today :)
    That was actually just a reference to an anonymous sub I just described, not a real closure..

    $a = sub { if($joe){somesub($arg1,$arg2);} }

    would do just the same..
    //mikkoH

      Ah, but it could be <grin>, its just a question of when you want $arg1 and $arg2 defined... maybe kael wanted the args declared when $a is declared....
      sub func{ die 'func takes 2 args' unless 2 == @_; my ( $arg1, $arg2 ) = @_; return sub { somesub($arg1,$arg2) if($joe) } } $a=&func( $somearg, $someotherarg ); # do stuff.. # call the function &$a;