Bonjour j'ai récupérer sur le net un crawler en perl , il marche parfaitement si ce n'est qu'il produit des doublons dans la array @links , j'ai bien tenté d'arranger sa e utilisant un hash mais rien a faire je n'y arrive pas , il me faut l'aide plus fort que moi en perl pour régler ce problème merci , d'avance pout tout coup de main ou idée
le problème vient de la
J'ai tenter de supprimé les doublons de $link et @links grace a des codes comme celui ci notament

Code:
#!/usr/bin/perl -w
use strict;
use warnings;
my $VERSION = "Bot/1.01";
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
$| = 1;
sub spider (%);
spider URL => '$url';
sub spider (%) {
my %args = @_;
my @startlinks = ("http://www.free.fr");
push(@startlinks, $args{URL});
my $ua = LWP::UserAgent->new;
$ua->agent('Mozilla/5.0 (compatible;)');
WORKLOOP: while (my $link = shift @startlinks) {
for (my $i = 0; $i< $#startlinks; $i++) {
next WORKLOOP if $link eq $startlinks[$i];
}
print ">>>>> working on $link\n";
HTML::LinkExtor->new(
sub {
my ($t, %a) = @_;
my @links = map { url($_, $link)->abs() }
grep { defined } @a{qw/href img/};
foreach my $start_link (@startlinks) {
my $i = 0;
for (0 .. $#links) {
if ($links[$i++] eq $start_link) {
$links[$i -1] = "'REMOVE'";
}
}
}
@links = sort @links;
for (my $i = 0; $i< $#links; $i++) {
$links[$i] = "'REMOVE'" if $links[$i] eq $links[$i +1];
}
@links = grep { $_ ne "'REMOVE'" } @links;
print "+ $_\n" foreach @links;
push @startlinks, @links if @links;
} ) -> parse(
do {
my $r = $ua->simple_request
(HTTP::Request->new("GET", $link));
$r->content_type eq "text/html" ? $r->content : "";
}
)
}
}
le problème vient de la
Code:
HTML::LinkExtor->new(
sub {
my ($t, %a) = @_;
my @links = map { url($_, $link)->abs() }
grep { defined } @a{qw/href img/};
foreach my $start_link (@startlinks) {
my $i = 0;
for (0 .. $#links) {
if ($links[$i++] eq $start_link) {
$links[$i -1] = "'REMOVE'";
}
}
}
@links = sort @links;
for (my $i = 0; $i< $#links; $i++) {
$links[$i] = "'REMOVE'" if $links[$i] eq $links[$i +1];
}
@links = grep { $_ ne "'REMOVE'" } @links;
print "+ $_\n" foreach @links;
push @startlinks, @links if @links;
} ) -> parse(
do {
my $r = $ua->simple_request
(HTTP::Request->new("GET", $link));
$r->content_type eq "text/html" ? $r->content : "";
}
)
J'ai tenter de supprimé les doublons de $link et @links grace a des codes comme celui ci notament
Code:
my %h_unique;
foreach my $ligne ( @links )
{
$h_unique{$ligne} = undef;
}
@links = keys %h_unique;