I would probably use LWP::Simple to verify that the link exists.

use strict; use warnings; use LWP::Simple; my $data_out_file = $ARGV[0] || 'links.txt'; open my $out_handle, '>', $data_out_file or die $!; for my $index ( 0000 .. 1000 ) { my $serial = sprintf "%04s", $index; my $site = qq(http://somewebsite/65081$serial.jpg); sleep 1; next unless head( $site ); my $link = qq(<img src = ") . $site . qq(">); print $out_handle $link, "\n"; } close $out_handle or die $!;

The head() function grabs the document header, which should tell you if it exists or not. In scalar context it simply returns true if successful.

Update: Added sleep 1; to throttle how quickly you'll be hitting the site. It now will take your script 1000 seconds to execute (almost 17 minutes) but you will avoid overloading the remote server. ...always best to play nice.


Dave


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 davido
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.