in reply to Please help me in goto statement

I presume you got an error message of the form Exiting subroutine via goto. Which is what you are trying to do, and isn't allowed.

I don't think you need the goto - I would check the return value of the eval, and exit if the eval succeeded. Or rather, only execute the second ping if the first failed. Something like this (untested):

# # Generalize to multiple ips # my @ips = ("192.168.0.0", "google.com"); $SIG{INT} = sub { print "Caught SIGINT: $?\n"; die if $?; }; foreach my $ip (@ips) { print $ip, "\n"; last if eval {`ping $ip`; 1}; }
Note that I do not wrap the eval in a pointless do construct, I'm not needing a flag variable, and I'm not storing the output of ping in a variable that I'm not going to use.

Replies are listed 'Best First'.
Re^2: Please help me in goto statement
by ikegami (Patriarch) on Jun 05, 2009 at 15:02 UTC
    Change
    last if eval {`ping $ip`; 1};
    to
    last if eval { `ping $ip`; !$? };
    and you now check the value returned by ping as well.