Bill,

I tried to run your code, but had to remove
use strict to get it to run

Can you explain this to a perl newbie?

--

Regards 
Jay


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of $Bill
Luebkert
Sent: 15 June 2004 02:54
To: Viswanatha Rao
Cc: [EMAIL PROTECTED]
Subject: Re: bitwise AND operation on IP addr and subnet mask in perl


Viswanatha Rao wrote:

> Hello,
> 
>  
> 
> I have to perform a bitwise AND operation on an IP address and a 
> subnet mask, to generate a network number and host ID. Can anyone tell

> me how to do this?

Try something like:

use strict;

my @ip = split /\./, '192.168.0.1';

my $ip = 0;
$ip = ($ip << 8) | $_ foreach @ip;

my $mask = 0xffff0000;
my $net = $ip & $mask;

printf "ip=%u (%08x), mask=%u (%08x), net %u (%08x)\n", $ip, $ip, $mask,
$mask,
  $net, $net;

__END__

-- 
  ,-/-  __      _  _         $Bill Luebkert
Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic
http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to