That's a clever way to handle the indexing problem, but you're still pulling the rug out from under your loop array. What happens when the list of aliases refers to something off beyond the new end of the array?

Splicing out elements from the loop array causes the skips. Copying downward to fill the gap makes the next element drop out of the loop. The top of the array moves down but aliased references to its elements remain unchanged.

Here's a safe way to remove elements from an array in a for loop. Use indexes and work from the top of the array down:

foreach my $index (reverse 0 .. $#links) { $response = $browser->get($links[$index]); splice(@links, $index, 1) unless $response->content_type eq 'text/html' || $response->content_type eq 'text/plain'; }
It would be more economical to work with head instead of get, but many sites deny head requests for no good reason.

Update: fizbin's grep suggestion is most likely a better way to do what you want. ++frodo72's addition of checking the $response for success.

After Compline,
Zaxo


In reply to Re: Checking URL's and deleting element arrays without HTML by Zaxo
in thread 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.