Useless use of a constant in void context

Discussion in 'Perl Misc' started by makko, Sep 16, 2005.

  1. makko

    makko Guest

    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--;
    }
    }
     
    makko, Sep 16, 2005
    #1
    1. Advertising

  2. makko

    Eric Bohlman Guest

    "makko" <> wrote in news:1126881846.704693.241920
    @g14g2000cwa.googlegroups.com:

    > 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.
     
    Eric Bohlman, Sep 16, 2005
    #2
    1. Advertising

  3. makko

    makko Guest

    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 *** #
     
    makko, Sep 19, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom Reilly
    Replies:
    5
    Views:
    429
    Gavin Kistner
    Nov 24, 2005
  2. George R. Gonzalez

    Useless use of private variable in void context ... ?

    George R. Gonzalez, Aug 8, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    223
    Brian McCauley
    Aug 8, 2003
  3. jon rogers
    Replies:
    3
    Views:
    264
    Eric J. Roode
    Dec 4, 2003
  4. Marek
    Replies:
    24
    Views:
    732
    Dr.Ruud
    Jun 16, 2007
  5. Replies:
    7
    Views:
    182
    Peter J. Holzer
    Dec 15, 2007
Loading...

Share This Page