Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Welcome to the Monastery
 
PerlMonks  

Re: IP operation trouble

by naChoZ (Curate)
on Jan 12, 2005 at 09:08 UTC ( [id://421604]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to IP operation trouble

It's because $binaddr only lives within the eval block. Ditch the eval block and you should be ok.

Update:
I fiddled with it a little just because I've never really messed with binary operations.

#!/usr/local/bin/perl -w use strict; use Net::IP qw/:PROC/; # # create your Net::IP object # my $ip_addr = Net::IP->new( "192.168.0.20" ); # # $ip_int becomes a Math::BigInt object # my $ip_int = ip_bintoint( $ip_addr->binip ); print "IP Address: ", $ip_addr->ip, "\nBin: ", $ip_addr->binip, "\nInt: ", $ip_int->numify(), "\n"; # # turn the Integer into a vanilla scalar # my $int_ip = $ip_int->numify(); # # Now start from the integer and go backwards # my $bin_from_int = sprintf( "%b", $int_ip); my $ip_from_bin = ip_bintoip( $bin_from_int, 4); print "\n\nInt: $int_ip\n", "Bin: $bin_from_int\n", "IP: ", $ip_from_bin, "\n";

--
"This alcoholism thing, I think it's just clever propaganda produced by people who want you to buy more bottled water." -- pedestrianwolf

Replies are listed 'Best First'.
Re^2: IP operation trouble
by fauria (Deacon) on Jan 12, 2005 at 09:27 UTC
    Hi there, The purpose of the eval block was to ensure there was not any error in the function, without it there happens the same. Thanks anyway

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://421604]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.