Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How to handle Net::Address::IP::Local'->public when we are not connected to internet

by sundialsvc4 (Abbot)
on Jan 19, 2015 at 17:38 UTC ( [id://1113790]=note: print w/replies, xml ) Need Help??


in reply to How to handle Net::Address::IP::Local'->public when we are not connected to internet

The eval strategy should work, if the package is indeed throwing an exception (which eval will catch).   But, notice that in the example code above, the value of $@ was printed.   So, the message would appear to “still show up,” even though this time it’s coming from that print statement.

Add two different print statements, one to if part and a different one to the else part, so that you can clearly see which one was executed.

It is proper behavior for the package to have thrown an exception (i.e. die()) in a case where, due to not being connected to the Internet (and therefore having no “local IP-address” at all), no value could sensibly be returned.   You just have to catch that exception, and eval should do that.

Replies are listed 'Best First'.
Re^2: How to handle Net::Address::IP::Local'->public when we are not connected to internet
by Anonymous Monk on Jan 19, 2015 at 17:50 UTC
    Hii, Thamks for the answer. I get this error from that code :
    Unable to create UDP socket: A socket operation was attempted to an un +reachable network....
    And don't this static IP return handle this error ? I mean doing this :
    return $address='192.80.160.16';
    should return return '192.80.160.16' instead of this error message. so how to get rid of this error and return '192.80.160.16' when there is no IP recived (when disconnected) otherwise return the real IP which it receives.
      Just don't print $@ if you don't want this message to be printed.

      Je suis Charlie.
      Instead of using eval string, why don't you simply type it without all the extra quotes?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found