I have an array of URL's which i want to check and remove the elements that haven't got plain text or HTML in them(a URL ending with .pdf for example should be deleted). Here is what i have written:
use LWP; my $browser = LWP::UserAgent->new(); my $index = 0; my $response = $browser->get($url_name); foreach (@links) { $response = $browser->get($_); if (($response->content_type eq 'text/html') || ($response->conte +nt_type eq 'text/plain')) { $index++; } else { splice(@links, $index, 1); } } foreach (@links) { print "$_\n"; }
The idea is that pages with the content i need (plain text or HTML) will remain in the array and the loop will move onto the next element to check that. If the loop finds an element to be deleted it should use the splice function to delete it(which means after deleting an element the next element in the array will take its place e.g. if i delete $links5 then $links6 will become $links5 and so on ,so there's no need to move in the index one up. Hope this made sense).
Hope someone can point out what am doing wrong.Thanks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |