|Syntactic Confectionery Delight|
Re: Check links.. if they do exist, then print link to file...but how do i check the existance of a link?(validity?)by Albannach (Prior)
|on Jul 27, 2006 at 19:20 UTC||Need Help??|
For starters, your $lead fiddling would be best replaced by a simple sprintf or perhaps use Perl's automagical incrementing:
will do what you want with much less fuss.
To your main question, in order to discover whether these JPGs actually exist, why not just download them since you want to look at them anyway, and for that you should find LWP::Simple's getstore() handy. If you really don't want to download them, then just use the head() function to see what the server will offer for each filename, and act accordingly.
One more thing, you should really make a habit of using the 3-arg version of open.
Update: Yes of course, silly me!
Update 2: In response to rodion's excellent question, I did a little reading and my interpretation is that at least for HTML 1.1, the HEAD should return exactly what a simple GET returns, minus the message body content. That implies (to the optimist in me at least) that the HEAD should not return if the GET would not. In fact, in section 9.4 (page 53 of RFC 2616), it notes that HEAD is often used for testing link validity. It would seem that for compliant servers at least, using HEAD should work. Corrections or clarifications are welcome!