in reply to Re^3: Net::Patricia - Perl Module for IP lookup
in thread Net::Patricia - Perl Module for IP lookup

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^4: Net::Patricia - Perl Module for IP lookup

Replies are listed 'Best First'.
Re^5: Net::Patricia - Perl Module for IP lookup
by Corion (Patriarch) on Aug 15, 2012 at 11:29 UTC

    What is your code, and what is your data? Please also describe what you expect as output and how your program fails to produce the output you want.

    Please reduce your code to about 20 lines before you post it, and make sure that your code still compiles and still reproduces the problem you encounter.

      use Net::Patricia; my $pt = new Net::Patricia; my @ar = ("82.94.229.0/24", "81.52.140.0/24"); $pt->add_string(@ar, "@ar"); my $dude = $pt->match_string('81.52.140.209'); print "$dude\n";
      This code i have written just for test because the data that i have is in different text files, but i can understand how this module works. From the above code i expect the following output  IP 81.52.140.209 reached 81.52.140.0/24

        ->add_string does not take an array as its first parameter, and it is documented to only take one or two parameters overall. As your array @ar contains two elements, your call is equivalent to

        my @ar = ("82.94.229.0/24", "81.52.140.0/24"); $pt->add_string("82.94.229.0/24", "81.52.140.0/24", "82.94.229.0/24 8 +1.52.140.0/24");

        I don't know what this means to Net::Patricia, but you will either need to read the documentation for Net::Patricia closer or learn more about Perl and how it flattens lists.

        Your use of add_string looks wrong according to the documentation which gives the function interface as:

        $pt->add_string(key_string[,user_data]);

        Note that the [,user_data] means you can provide optional user data along with the string. However you call the function passing an array containing two strings then follow up with a third string formed by interpolating the same array.

        I haven't the module installed so I won't offer any code as I can't test it. The documentation seems pretty clear to me so I suggest you re-read the docs and take a careful look at the example code. Note that add_string returns undef on failure so you can easily check to see that the module isn't grumpy with the way you are using it.

        True laziness is hard work
        foreach my $pat (@ar) { $pt->add_string($pat); }