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


In reply to Re: IP operation trouble by naChoZ
in thread IP operation trouble by fauria

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.