ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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--;
}
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.