小编Sam*_*Sam的帖子

Perl按位并给我时髦的结果

我正在编写一个perl脚本来比较使用perls按位AND运算符的两个IP地址.但我得到了一些非常时髦的结果.我是perl的新手所以也许有人可以给我一些指示.

继承我的小脚本:

#!/usr/bin/perl

$address = "172.34.12.0";
$address2 = "255.255.255.0";

@octets = split (/\./,$address);
@octets2 = split (/\./,$address2);

#Funky results when doing a bitwise AND
#This outputs "050 24 00 0" What's going on here?
print $octets[0] & $octets2[0], "\n";
print $octets[1] & $octets2[1], "\n";
print $octets[2] & $octets2[2], "\n";
print $octets[3] & $octets2[3], "\n";

#Results are what I want when doing it as literals
#This outputs "172 34 12 0"
print 172 & 255, "\n";
print 34 & 255, "\n"; …
Run Code Online (Sandbox Code Playgroud)

ip perl parsing bit-manipulation

8
推荐指数
5
解决办法
499
查看次数

标签 统计

bit-manipulation ×1

ip ×1

parsing ×1

perl ×1