Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by ppp (Acolyte)
on Jan 19, 2015 at 16:38 UTC ( [id://1113777]=note: print w/replies, xml ) Need Help??


in reply to Re: 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

Yes it gives some UDP socket connection couldnt created.. type of error. I dont have that in pc here. I saw in my school this morning. But error was linke some .. UDP socket cudnt create.. So how to handle it . I t gives this error because there is no internet access and even then i am trying to get IP , so no connection i guess thats why..

But how i can handle it ? Because if i print it like this :

print "adress is : 'Net::Address::IP::Local'->public";
Then it just print:
adress is :
Now it even do not print 0 or null so that i could habdle it like this if($adress=null) {do this} How to handle ?
  • Comment on Re^2: How to handle Net::Address::IP::Local'->public when we are not connected to internet
  • Select or Download Code

Replies are listed 'Best First'.
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

    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
      I got ur point.. all is well now .. Thnaks :)
      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.
Re^3: How to handle Net::Address::IP::Local'->public when we are not connected to internet
by Your Mother (Archbishop) on Jan 19, 2015 at 21:29 UTC

    If you’re really doing this, and it’s not just a typo, it’s not what you think. Package and object stuff does not work as interpolated strings. Well, not without trickery. This–

    print "adress is : 'Net::Address::IP::Local'->public";

    –will print this–

    adress is : 'Net::Address::IP::Local'->public

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found