I don't think it's a good idea to include standard input for class methods, because then those functions couldn't be called without them waiting for input which there probably is none of. Anyway, here is my script:
#!/usr/bin/perl require '/home/me/perl/myclass.pl'; print "Enter your username: "; chomp($username = <STDIN>); print "Enter your password: "; system("stty -echo"); chomp($password = <STDIN>); system("stty echo"); print "\n"; $bot = new Myclass $username, $password; if(!$bot->login){ print "Enter your username: "; chomp($username = <STDIN>); print "Enter your password: "; system("stty -echo"); chomp($password = <STDIN>); system("stty echo"); print "\n"; } my $action = { 'do' => 'do_this', 'change' => 'change_that' }; print "Menu: "; my $menu_item; while(chomp($menu_item = <STDIN>) && $menu_item ne 'logout'){ if (defined $action->{$menu_item}){ my $method = $action->{$menu_item}; $bot->$method; }else{ print "I didn't understand the command.\n"; } print "Menu: "; } if($menu_item eq 'logout'){ $bot->logout; }else{ print "wtf?\n"; }
Basically, change_that is a subroutine/method of Myclass, and I want to pass arguments to it, using standard input. One way would be having change_that use <STDIN> in the actual code of the class, but that would be too unusable. Should I create a separate function for each item of $action? How would you wise Perl Monks do it in the cleanest and most efficient manner? If you need clarification, I would be happy. If you run my code you get a login prompt, then you are allowed to submit any command you want, until you say "logout." But lets say I use command "change that", which will call method "change_that", I want it to prompt the user for the data it needs to change.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.