Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Passing arguments to functions.

by Anonymous Monk
on Apr 25, 2012 at 11:17 UTC ( [id://967053]=note: print w/replies, xml ) Need Help??


in reply to Passing arguments to functions.

What is a "function module"? An example of what $command actually contains would help.

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
    Hi, Thanks for your reply, i will try your approach and let you know the results. $command is a normal perl function , it might do anything as you defined it can just print the passed arguments as well. In my case $command is a value got by parsing an xml which is a name of a function.. $command = launchapp; launchapp is the function name which needs to be triggered.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://967053]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2026-04-14 08:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.