Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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 ( #564206=note: print w/ replies, xml ) Need Help??


in reply to Check links.. if they do exist, then print link to file...but how do i check the existance of a link?(validity?)

For starters, your $lead fiddling would be best replaced by a simple sprintf or perhaps use Perl's automagical incrementing:

$num = '0000'; for(1..1000) { print ++$num,"\n"; }
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!

--
I'd like to be able to assign to an luser


Comment on Re: Check links.. if they do exist, then print link to file...but how do i check the existance of a link?(validity?)
Select or Download Code
Re^2: Check links.. if they do exist, then print link to file...but how do i check the existance of a link?(validity?)
by Anonymous Monk on Jul 27, 2006 at 20:14 UTC
    $num = '0000'; for(1..1000) { print ++$num,"\n"; }
    Or even
    for my $num ('0000' .. '1000') { ... }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://564206]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-07-14 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (255 votes), past polls