in reply to Passing references to subroutines with parameters

You might do it this way:
sub_to_receive('123', \&sub_to_be_passed, 'xyz'); sub sub_to_be_passed { my ($one) = shift; my ($two) = shift; print "One: $one\n"; print "Two: $two\n"; } sub sub_to_receive { my ($x, $sub_to_run, @args) = @_; $sub_to_run->(@args, "lalala"); }

Replies are listed 'Best First'.
Re: Re: Passing references to subroutines with parameters
by clscott (Friar) on Jul 13, 2001 at 18:53 UTC
    Aijin!

    I would follow runrigs lead. It's flexible and straight forward, and makes it easy to pass multiple arguments to sub_to_pass and the interface is consistent with fun things like  system.

    sub sub_to_receive { # Example usage # sub_to_receive('123', \&sub_to_be_passed, 'arg'); # sub_to_receive('123', \&sub_to_be_passed, 'arg1', 'arg2'); # sub_to_receive('123', \&sub_to_be_passed, @args); # my ($x, $sub_to_run, @args) = @_; $sub_to_run->(@args, "lalala"); }

    --
    Clayton aka "Tex"