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).
I don't know where the looping should take place, so confused hehe.. thanksuse 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; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |