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

Try the same with eval. Here is the code, I have added eval part

use strict; use warnings; use Net::Address::IP::Local; print ReturnIpAddress(); sub ReturnIpAddress { select STDOUT; eval{ $address = 'Net::Address::IP::Local'->public ; ## Rece +iving the current IP ## }; if ($@) { print "$@"; return '192.80.160.16'; ##If No IP address received th +en return a static IP of order "192....." } else { return $address; } }

All is well
  • Comment on Re^3: How to handle Net::Address::IP::Local'->public when we are not connected to internet
  • Download Code

Replies are listed 'Best First'.
Re^4: How to handle Net::Address::IP::Local'->public when we are not connected to internet
by ppp (Acolyte) on Jan 19, 2015 at 18:11 UTC
    I got ur point.. all is well now .. Thnaks :)
Re^4: How to handle Net::Address::IP::Local'->public when we are not connected to internet
by Anonymous Monk on Jan 19, 2015 at 17:12 UTC
    Same error :
    Unable to create UDP socket: A socket operation was attempted to an un +reachable network. at C:/Perl/site/lib/Net/Address/IP/Local.pm line 166. 192.80.160.16
      No, it is no longer a fatal error. The program just does what you asked it to do: it prints the content of $@. And then it continues and prints your static IP address, which is enough to prove that the program does not die because of the socket exception.

      Je suis Charlie.