Hi to all the monks, am having some trouble with a piece of code i have written which doesn't seem to do what its supposed to.

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


In reply to Checking URL's and deleting element arrays without HTML by lampros21_7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.