perl cgi url exists

perl cgi url exists
That’s a somewhat tall order. Unlike a file system which allows you to ask, “Does file X exist?” the web is more like, “Show me file/resource X or tell me why you won’t/can’t.”
This would do the trick for many cases though.
use strict;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->agent_alias('Windows IE 6');
my $uri_to_check = shift || die "Give a URI!\n";
$mech->get( $uri_to_check );
if ( $mech->success ) { print "Valid: $uri_to_check\n"; } else { warn "Invalid! $uri_to_check\n"; warn " Status: ", $mech->status(), "\n"; }
There are much more simple and idiomatic ways to write that—even in one line—using something like LWP instead of WWW::Mechanize. It has additional problems though in that some servers won’t take requests from LWP so you might get false negatives unless you call your requesting agent a standard browser name as we do with the alias() above.
[close] Permanent link · http://querylog.com/q/perl+cgi+url+exists

Suggested HTML for linking:
Link preview: perl cgi url exists
21 October 2005 · Internet & computing
The page found by the original query:
CGI with dispatch hash
Browse by the page—15 Q&R each
« previous | more »