in reply to Passing arguments to functions.
I recommend passing a code reference as first argument, this is the most generic way to solve this kind of problem.
use 5.010; use strictures; sub execute_command { my ($code, $params) = @_; say 'Inside executeCommand'; say 'Currently executing: ', ref $code; foreach my $element (@{ $params }) { say "Parameter: $element"; $code->($element); } } my $command = sub { # I am going to print the arguments I receive! say @_; }; execute_command($command, \@paramlist);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing arguments to functions.
by balajinagaraju (Sexton) on Apr 25, 2012 at 11:29 UTC |