Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by vinoth.ree (Monsignor)
on Jan 19, 2015 at 16:49 UTC ( [id://1113779]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

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

    No recent polls found