Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Please help me in goto statement

by JavaFan (Canon)
on Jun 05, 2009 at 12:24 UTC ( #768774=note: print w/replies, xml ) Need Help??

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 = ("", ""); $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
    last if eval {`ping $ip`; 1};
    last if eval { `ping $ip`; !$? };
    and you now check the value returned by ping as well.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://768774]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2022-08-19 20:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found