First of all, i'm not the original poster but with the same problem. I'm trying to wrote a small script what does next things: Logs into router over telnet (that part works). Send command to the router and get the necessary date (also works). When i need some extra features to configure in router then a press a certain button, subroutine associated with the button does what it supposed to do and the that's basically it. What i'm trying to do is: Add a Button to the page and this button calls first subroutine. My first sub is sub telnet { logging into router only!}; When i press the button it should call sub called &telnet(); and after successful login it should call another sub what i define and all that should be working on the same page. Without sub pages on my site. Example part of the script that's working fine:
#!/usr/bin/perl -w print "Content-type: text/html\r\n\r\n"; use Net::Telnet (); use CGI qw (:standard);; my $user = 'username'; my $pass = 'password'; my $host = "192.168.1.254"; $t = new Net::Telnet (Timeout => 1, Prompt => '/\$ $/i'); $t->open($host); $t->waitfor('/: $/i'); $t->print($user); $t->waitfor('/ : $/i'); $t->print($pass); $t->waitfor('/>$/i'); @lines = $t->print ("system settime"); # it takes router uptime info ($output) = $t->waitfor('/=>$/i'); print "<pre>"; #for nice output print $output; $t->print("exit"); print "</pre>"; #for nice output
This is all in one script to show you working part. I know how to make a sub but How to call it with the button. How to call several sub one after one just cliking the button. Second sub contains something like that:
@lines = $t->print ("turn off dhcp server"); #for example ($output) = $t->waitfor('/=>$/i'); #waits prompt print $output;
"turn off dhcp server" - whatever command i will wrote there. It's not a good idea to call all subroutines at once, one bye one. It's not necessary, could make something worse etc. To make this "page" more compact i would like to call those subs in the script itself with a button. Any hints, examples appreciated!

In reply to Re^4: Calling internal subroutine from a form submit by Anonymous Monk
in thread Calling internal subroutine from a form submit by colinb444

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.