in reply to I'm creating a menu and using the input as methods. How do I use arguments?

To accomplish what you asked for, I would use callbacks.

You can call $method like this:

$bot->$method(\&GetInput, \&ShowOutput); # In your main program, you have to define sub GetInput{...}, # and sub ShowOutput{...} # Alternatively, use anonymous subs : $bot->$method(sub{print $_[0]; return scalar <>}, sub{print $_[0] . "\n"});
(Untested).

To complete the picture, here is how $method would use the passed callbacks ..

sub method{ my ($self, $getInput,$SendOutput) = @_; my $input = $getInput->("Optional PROMPT parameter, if any\n"); #.. Do something with $input, and generate $output $SendOutput->($output); }

     Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

Replies are listed 'Best First'.
Re^2: I'm creating a menu and using the input as methods. How do I use arguments?
by skrapasor (Novice) on Jun 26, 2008 at 01:12 UTC
    I'm not sure what the GetInput subroutine would be. It seems like it would be the same for every method, but some methods need multiple parameters and the prompt would be different, how would I implement that?
      You have the option to use a single "GetInput" subroutine, or pass references to different subs to different methods.

      Your implementation of "GetInput" can use as many parameters as you like - you can make some, or all optional - that way you could use a single subroutine for all methods.

      In the example I showed, you certainly CAN pass different prompts back to GetInput.

      I had already given you sample code for GetInput - you can use the contents of the first Anonymous sub.

      I would suggest you try implementing the suggestion I provided, and post back specific problems you run into - we monks are happy to help you understand and troubleshoot specific issues, but are reluctant to solve the entire problem for you. This helps you become self-sufficient, while reducing our liability for misunderstanding your issues.

           Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

        Yeah I know I just got really confused on this one, but I'm working on it.