cummiro has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am trying to use the storeNetBlock feature in the Net::Netmask module. I am trying to load a file into a table called $acl_tbl. The output is created from an acl file, which I am parsing for future use. I can get the storeNetBlock feature to work when I am not defining a table name, but when I define the $acl_table I see errors. Here is the code:

sub acl_parse { open (INFILE1, "<$acl_file"); open (OUTFILE1, ">$acl_out"); open (TEST, ">$acl_dump"); while(<INFILE1>) { $_ =~ s/^\s+//; push(@acl, $_); foreach $acl(@acl) { @acl_parse = split(/\s/,$acl); } if ($acl_parse[2] ne "host") { print OUTFILE1 "$acl_parse[0]|$acl +_parse[1]|$acl_parse[2]|$acl_parse[3]|$acl_parse[4]|$acl_parse[5]\n"; my $b = "$acl_parse[2]#$acl_parse +[3]"; my $acl_block=new2 Net::Netmask ( +"$b"); $acl_block->storeNetblock([$acl_t +bl]); } } }

When I run the code, I get the following error:

Pseudo-hashes are deprecated at /usr/apps/ucm/perl_mod/lib/perl5/site_perl/5.8.8/Net/Netmask.pm line 265, <INFILE1> line 17. Pseudo-hashes are deprecated at /usr/apps/ucm/perl_mod/lib/perl5/site_perl/5.8.8/Net/Netmask.pm line 265, <INFILE1> line 17. No such pseudo-hash field "3637005816" at /usr/apps/ucm/perl_mod/lib/perl5/site_perl/5.8.8/Net/Netmask.pm line 265, <INFILE1> line 17.

I know you cannot combine an array with a hash, but I'm not clear how I am doing so and I'm having trouble finding examples. Thank you

Replies are listed 'Best First'.
Re: Using optional table option in Net::Netmask
by choroba (Cardinal) on Oct 20, 2011 at 15:29 UTC
    I suspect this line:
    my $acl_block=new2 Net::Netmask ( +"$b");
    $b is constructed as a string the line before, but according to the documentation, it should be an object.
      I've used Net::Netmask a few times. The new2 method looks ok. Looks like your trying to setup a Net::Netmask object using wild card bits instead of a subnet mask. I haven't done that before with Net::Netmask, but it looks like things went ok until line 17 of the input file. You also are using new2 which should return undef if fails. You could try adding a error check in there. Maybe the input isn't what you expected. my $acl_block = new2 Net::Netmask( $b ) or die $Net::Netmask::error to see if maybe the object isn't being created correctly and possibly why.
Re: Using optional table option in Net::Netmask
by mrstlee (Beadle) on Oct 21, 2011 at 14:40 UTC
    First thing I do in times like these:
    use Data::Dumper; ... print Dumper $b;
    Looks like the fn call expects a blessed hash - but gets an array ref?

      I ran Data::Dumper on both the $b and $acl_block values.

      ($b) = $VAR1 = '10.10.10.248#0.0.0.7'; (4acl_block) = $VAR1 = bless( { 'IBASE' => 168430328, 'BITS' => 29 }, 'Net::Netmask' ); Pseudo-hashes are deprecated at /usr/apps/ucm/perl_mod/lib/perl5/site_ +perl/5.8.8/Net/Netmask.pm line 265, <INFILE1> line 17. Pseudo-hashes are deprecated at /usr/apps/ucm/perl_mod/lib/perl5/site_ +perl/5.8.8/Net/Netmask.pm line 265, <INFILE1> line 17. No such pseudo-hash field "168430328" at /usr/apps/ucm/perl_mod/lib/pe +rl5/site_perl/5.8.8/Net/Netmask.pm line 265, <INFILE1> line 17.

      It looks like both values are being interpreted correctly but I'm still seeing the same issue. Thanks......

        Cracked it I think.
        The documentation is misleading:
        ->storeNetblock([$t])
        It doesn't mean pass an array - it means that $t is an optional argument.
        This works for me:
        my $acl_tbl = {}; $acl_block->storeNetblock($acl_tbl);