I tried something but the problem is it won't go back to the main menu when I picked 1 or 2.

Here's my test code for checking ping and DNS of a host (just a part of it for the menu testing).

use Net::Ping; require LWP::UserAgent; use HTTP::Headers; use NET::DNS; use Socket; use NET::IP; use Time::HiRes qw( gettimeofday ); my @url = ('www.google.com', 'www.yahoo.com'); sub exit_st(); sub check_ping(); sub check_dns(); open(OUTFILE, ">", "check_result3.txt") ? print "\n\nProcessing the re +sult...\n\n" : die "Can't process the result, unable to write output: + $!"; %action = ( '1' => \&check_ping, '2' => \&check_dns, '3' => \&exit_st,); print <<"EOT"; Select one of: 1. Ping Check 2. DNS Check 3. Exit EOT print "Enter your choice here: "; my $menu_item = <>; chomp($menu_item); (defined $action{$menu_item}) ? $action{$menu_item}->() : print "Wrong + input. \n"; exit 0; #Check Ping sub check_ping() { print OUTFILE "*Ping Result*\n"; my $p = Net::Ping->new("icmp"); ($p->ping($url[0])) ? print "$url[0] is alive.\n" : print "$url[0] is +not alive\n"; ($p->ping($url[1])) ? print "$url[1] is alive.\n\n" : print "$url[1] i +s not alive.\n\n"; return 0; } #Check DNS sub check_dns() { print OUTFILE "*DNS Result*\n"; $ip1 = gethostbyname($url[0]) || die "error - gethostbyname: $!\n\n"; $hostip1 = inet_ntoa($ip1) || die "error - inet_ntoa: $!\n\n"; print $url[0], " = ", $hostip1; return; }
I don't know where the looping should take place, so confused hehe.. thanks

In reply to Re^2: How to make a menu using my subroutines? by astronogun
in thread How to make a menu using my subroutines? by astronogun

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.