Subject: | About using sort function with magical variables $a and $b |
Hello!
I'm using Net::Netmask within a part of staticperl (perl 5.12.4, x86_64
at linux host) and found next message when try to load module:
Can't use "my $b" in sort comparison at Net/Netmask.pm line 1
According to "Poor Diagnosis of sort Errors" at http://www.perl.com/
pub/2000/04/ I'm applied a patch to Netmask.pm:
--- /home/tvv/.staticperl/lib/Net/Netmask.pm 2012-05-02
13:23:10.000000000 +0400
+++ Netmask.pm 2012-05-02 13:23:03.000000000 +0400
@@ -265,8 +265,8 @@
$t->{$base} = [] unless exists $t->{$base};
my $mb = maxblock($this);
- my $b = $this->{'BITS'};
- my $i = $b - $mb;
+ my $bits = $this->{'BITS'};
+ my $i = $bits - $mb;
$t->{$base}->[$i] = $this;
}
@@ -279,8 +279,8 @@
my $base = $this->{'IBASE'};
my $mb = maxblock($this);
- my $b = $this->{'BITS'};
- my $i = $b - $mb;
+ my $bits = $this->{'BITS'};
+ my $i = $bits - $mb;
return unless defined $t->{$base};
@@ -301,13 +301,13 @@
return unless defined $ip;
my %done;
- for (my $b = 32; $b >= 0; $b--) {
- my $nb = $ip & $imask[$b];
+ for (my $bits = 32; $bits >= 0; $bits--) {
+ my $nb = $ip & $imask[$bits];
next unless exists $t->{$nb};
my $mb = imaxblock($nb, 32);
next if $done{$mb}++;
my $i = $b - $mb;
- confess "$mb, $b, $ipquad, $nb" if ($i < 0 or $i > 32);
+ confess "$mb, $bits, $ipquad, $nb" if ($i < 0 or $i >
32);
while ($i >= 0) {
return $t->{$nb}->[$i]
if defined $t->{$nb}->[$i];
@@ -332,13 +332,13 @@
$mask = 32;
}
- for (my $b = 0; $b <= $mask; $b++) {
- my $nb = $ip & $imask[$b];;
+ for (my $bits = 0; $bits <= $mask; $bits++) {
+ my $nb = $ip & $imask[$bits];;
next unless exists $t->{$nb};
my $mb = imaxblock($nb, $mask);
- my $i = $b - $mb;
- confess "$mb, $b, $ipquad, $nb" if $i < 0;
- confess "$mb, $b, $ipquad, $nb" if $i > 32;
+ my $i = $bits - $mb;
+ confess "$mb, $bits, $ipquad, $nb" if $i < 0;
+ confess "$mb, $bits, $ipquad, $nb" if $i > 32;
while ($i >= 0) {
return $t->{$nb}->[$i]
if defined $t->{$nb}->[$i];
@@ -356,14 +356,14 @@
my $ip = quad2int($ipquad);
my %done;
- for (my $b = 32; $b >= 0; $b--) {
+ for (my $bits = 32; $bits >= 0; $bits--) {
my $nb = $ip & $imask[$b];
next unless exists $t->{$nb};
my $mb = imaxblock($nb, 32);
next if $done{$mb}++;
- my $i = $b - $mb;
- confess "$mb, $b, $ipquad, $nb" if $i < 0;
- confess "$mb, $b, $ipquad, $nb" if $i > 32;
+ my $i = $bits - $mb;
+ confess "$mb, $bits, $ipquad, $nb" if $i < 0;
+ confess "$mb, $bits, $ipquad, $nb" if $i > 32;
while ($i >= 0) {
push(@ary, $t->{$nb}->[$i])
if defined $t->{$nb}->[$i];
@@ -397,8 +397,8 @@
my $base = $this->{'IBASE'};
my $mb = maxblock($this);
- my $b = $this->{'BITS'};
- my $i = $b - $mb;
+ my $bits = $this->{'BITS'};
+ my $i = $bits - $mb;
return defined $t->{$base}->[$i];
}
And now problem has gone. I never met this error before this moment,
may be you know where is problem is.
Thanks.