The CPAN module LWP::UserAgent provides a method "$ua->max_size( $bytes )" which allows you to gen just a little bit of content, just to make sure the link works.

If you set this before you issue a "$ua->get( $url )" request, you should be able to check for a "Client-Aborted" header in the response, as per the documentation.

Setting a maximum size allows you to make sure that you could get the document, without the program having to hang around waiting for the whole transfer. If you have a successful transfer, or a "Client-Aborted" header, you know that the link works and you can quickly move on to checking the next one.

Addendum: I just saw Albannach's suggestion for getting the header alone. Does anyone reading this know if there are cases (worth checking for) where you can get the header and can't get the content? If no one knows of any that are relevant to the OP, then just checking the header should be faster than getting a limited amount of content.


In reply to Re: Check links.. if they do exist, then print link to file...but how do i check the existance of a link?(validity?) by rodion
in thread Check links.. if they do exist, then print link to file...but how do i check the existance of a link?(validity?) by dark314

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.