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

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

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

    ->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.

Re^7: Net::Patricia - Perl Module for IP lookup
by GrandFather (Saint) on Aug 15, 2012 at 12:02 UTC

    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
Re^7: Net::Patricia - Perl Module for IP lookup
by jethro (Monsignor) on Aug 15, 2012 at 12:23 UTC
    foreach my $pat (@ar) { $pt->add_string($pat); }