Useless use of a constant in void context

M

makko

I wrote this perl script to generate reverse dns zonefiles but this
error keeps popping up. Line 45 is the end of the binary table. can
anyone detect what the problem is?;

"Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45.
Useless use of a constant in void context at inthezone2.pl line 45."

Here's the code:

##!/usr/bin/perl -T
# Copyright (C) 2005, Timothy Makobu
use warnings;
use strict;

# This program generates reverse DNS zonefiles for a given subnet.
unless($#ARGV+1 == 1)
{
print "This program generates reverse DNS zonefiles for a given
subnet.\n";
print "Usage inthezone.pl [ipblock]\n";
print "Example: inthezone2.pl 10.0.0.0/10\n";
exit 1;
}
my $subnet = $ARGV[0];
unless($subnet =~
m#^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})$#)
{
print "Invalid IP block\n";
exit 1;
}
# Here we go :)
my $slash = $5;
if($slash < 9)
{
print "Invalid IP block. Bigger than a class A block\n";
exit 1;
}
elsif($slash > 32)
{
print "There's no such thing on IPV4 doode, :-D\n";
exit 1;
}
my $bits = 32 - $slash;
my $decbits = 0;
my $reverse_dns = undef;
my $dbits = undef;
my $bitsc = undef
my %binarytable = (
1=>1,
2=>2,
3=>4,
4=>8,
5=>16,
6=>32,
7=>64,
8=>128);
while($bits)
{
$decbits += $binarytable{$bits};
$bits--;
}
if($bits <= 8)
{
open ZONE,">$1.$2.$3.db" or die $!;
select ZONE;
my $dbits = $decbits;
while($dbits)
{
$reverse_dns = "$dbits.$3.$2.$1.IN-ADDR.ARPA\n";
print $reverse_dns;
$dbits--;
}
close ZONE;
}
elsif($bits <= 16)
{
my $bitsc = $decbits - 255;
while($bitsc)
{
open ZONE,">$1.$2.$bitsc.db" or die $!;
select ZONE;
$dbits = 255;
while($dbits)
{
$reverse_dns = "$dbits.$bitsc.$2.$1.IN-ADDR.ARPA\n";
print $reverse_dns;
$dbits--;
}
close ZONE;
$bitsc--;
}
}
elsif($bits <=24)
{
$bitsc = $decbits - 255;
while($bitsc)
{
my $bitscc = 255;
while($bitscc)
{
open ZONE,">$1.$bitsc.$bitscc.db" or die $!;
select ZONE;
$dbits = 255;
while($dbits)
{
$reverse_dns = "$dbits.$3.$2.$1.IN-ADDR.ARPA\n";
print $reverse_dns;
$dbits--;
}
close ZONE;
$bitscc--;
}
$bitsc--;
}
}
 
E

Eric Bohlman

I wrote this perl script to generate reverse dns zonefiles but this
error keeps popping up. Line 45 is the end of the binary table. can
anyone detect what the problem is?;

"Useless use of a constant in void context at inthezone2.pl line 45.
my $bitsc = undef
my %binarytable = (
1=>1,
2=>2,
3=>4,
4=>8,
5=>16,
6=>32,
7=>64,
8=>128);

Note what's missing right before the *beginning* of the binary table.
 
M

makko

Oh my, thanx :D here's the working code:

#!/usr/bin/perl -T
#################################################
# #
# Reversedns.pl is a program that generates #
# reverse DNS zonefiles for a given subnet. #
# #
# Copyright (C) 2005, Timothy Makobu #
# #
#################################################
use warnings;
use strict;

unless($#ARGV+1 == 1)
{
print "\n\nreversedns.pl generates reverse DNS zonefiles for a given
subnet.\n";
print "Usage inthezone.pl [ipblock]\n";
print "Example: inthezone2.pl 10.0.0.0/10\n";
exit 1;
}
my $subnet = $ARGV[0];
unless($subnet =~
m#^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})$#)
{
print "Invalid IP block\n";
exit 1;
}
my $slash = $5;
if($slash < 9)
{
print "Invalid IP block. Bigger than a class A block\n";
exit 1;
}
elsif($slash > 32)
{
print "There's no such thing on IPV4 doode, :-D\n";
exit 1;
}

# Here we go :)
my $bits = 32 - $slash;
my $reverse_dns = undef;
my $dbits = 0;
my $bitc = 0;
my $decimal = 0;
my $zonenum = 0;
if($bits <= 8)
{
open ZONE,">$1.$2.$3.db" or die $!;
select ZONE;
$dbits = 255;
while($dbits)
{
$reverse_dns = "$dbits.$3.$2.$1.IN-ADDR.ARPA\n";
print $reverse_dns;
$dbits--;
}
close ZONE;
}
elsif($bits <= 16)
{
$bitc = $bits - 8;
$decimal = b2d($bitc);
while($decimal != -1)
{
$zonenum = $decimal+$3;
open ZONE,">$1.$2.$zonenum.db" or die $!;
select ZONE;
$dbits = 255;
while($dbits)
{
$reverse_dns = "$dbits.$zonenum.$2.$1.IN-ADDR.ARPA\n";
print $reverse_dns;
$dbits--;
}
close ZONE;
$decimal--;
}
}
elsif($bits <=24)
{
$bitc = $bits - 16;
$decimal = b2d($bitc);
while($decimal != -1)
{
my $bitscc = 255;
while($bitscc != -1)
{
$zonenum = $decimal+$2;
open ZONE,">$1.$zonenum.$bitscc.db" or die $!;
select ZONE;
$dbits = 255;
while($dbits)
{
$reverse_dns = "$dbits.$bitscc.$zonenum.$1.IN-ADDR.ARPA\n";
print $reverse_dns;
$dbits--;
}
close ZONE;
$bitscc--;
}
$decimal--;
}
}

#+++++++ SUB_ROUTINE(S) +++++++#

sub b2d
{
my $bits = shift;
my %binarytable = (
1=>1,
2=>2,
3=>4,
4=>8,
5=>16,
6=>32,
7=>64,
8=>128);
my $decbits=0;
while($bits)
{
$decbits += $binarytable{$bits};
$bits--;
}
return($decbits);
}

#+++++++++++++++++++++++++++++++++++++++#

exit 0;

# *** EOF *** #
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top