X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;ds=inline;f=perl%2FPrefix.pm;h=17ba83dca5b7ea6711c7b87fdbd2ce6f27e197ce;hb=3e78861c5df183d45e4dc69bcde40d9672ec7e58;hp=15b6752dbcbc2bfef0810e4d408a730273253be1;hpb=6b6eda0362049fd67809f2789e523708a1a8cb13;p=spider.git diff --git a/perl/Prefix.pm b/perl/Prefix.pm index 15b6752d..17ba83dc 100644 --- a/perl/Prefix.pm +++ b/perl/Prefix.pm @@ -149,9 +149,12 @@ sub extract foreach $call (split /,/, $calls) { # first check if the whole thing succeeds my @nout = get($call); - push @out, @nout if @nout; - next if @nout > 0 && $nout[0] eq $call; - + if (@nout && $nout[0] eq $call) { + dbg("got exact prefix: $nout[0]") if isdbg('prefix'); + push @out, @nout; + next; + } + # now split the call into parts if required @parts = ($call =~ '/') ? split('/', $call) : ($call); @@ -167,27 +170,42 @@ sub extract # can we resolve them by direct lookup foreach $p (@parts) { @nout = get($p); - push @out, @nout if @nout; - next if @nout > 0 && $nout[0] eq $call; + if (@nout && $nout[0] eq $call) { + dbg("got exact prefix: $nout[0]") if isdbg('prefix'); + push @out, @nout; + next; + } } } # which is the shortest part (first if equal)? + dbg("Parts: $call = " . join('|', @parts)) if isdbg('prefix'); $sp = $parts[0]; foreach $p (@parts) { - $sp = $p if length $sp > length $p; + $sp = $p if length $p < length $sp; } + $sp =~ s/-\d+$//; # remove any SSID + # # now start to resolve it from the left hand end # for ($i = 1; $i <= length $sp; ++$i) { # now start to resolve it from the right hand end for ($i = length $sp; $i >= 1; --$i) { - my @wout = get(substr($sp, 0, $i)); - last if @wout > 0 && $wout[0] gt $sp; + my $ssp = substr($sp, 0, $i); + my @wout = get($ssp); + if (isdbg('prefix')) { + my $part = $wout[0] || "*"; + dbg("Partial prefix: $sp $ssp $part" ); + } + next if @wout > 0 && $wout[0] gt $ssp; # last if @wout == 0; push @out, @wout; last if @wout; } } + if (isdbg('prefix')) { + my $dd = new Data::Dumper([ \@out ], [qw(@out)]); + dbg($dd->Dumpxs); + } return @out; }