I wonder why you need one reference to a subroutine without parameters and one with. Do you anticipate many different parameter combinations, each with its corresponding reference? Why not just invoke the reference to the subroutine with or without parameters?
knoppix@Microknoppix:~$ perl -Mstrict -wE ' > sub meth { say @_ ? qq{Got params: @_} : q{No params} } > > my $refToMeth = \ &meth; > $refToMeth->(); > say q{-} x 20; > $refToMeth->( qw{ a b c } );' No params -------------------- Got params: a b c knoppix@Microknoppix:~$
Or create the subroutine reference directly in the first place.
knoppix@Microknoppix:~$ perl -Mstrict -wE ' > my $refToMeth = sub { say @_ ? qq{Got params: @_} : q{No params} }; > > $refToMeth->(); > say q{-} x 20; > $refToMeth->( qw{ a b c } );' No params -------------------- Got params: a b c knoppix@Microknoppix:~$
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: how can I store a reference to a method/function along with the parameters?
by johngg
in thread how can I store a reference to a method/function along with the parameters?
by noelgolding
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |