Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
# The script take the URL list on the command line # So, you should call your script like this : # perl http://site/f1.html http://site/f2.html ... # Command line arguments are stored in the ARGV list. # For each URL in ARGV, place this current URL in $_ # $_ the the "default" variable in Perl. for (@ARGV){ # Remove the leading "http://" part of $_ s|http://||; # Extract the server name in $1 and the file name in $2 # from $_ (see "perlre" documentation for this) m|([^/]+)(.*)|; # Open a tcp socket connection to the server $1 on port 80 my $s=IO::Socket::INET->new( PeerAddr=>$1, PeerPort=>80, Proto=>'tcp +', Type=>SOCK_STREAM ); # Send a simple HTTP GET request to the server for # file $2 or "/" if $2 is not defined. print $s "GET ".($2||'/')." HTTP/1.0\nHost: $1 \n\n"; # Read the first line of the answer (with <$s>) from the # server and print "Link xxx is validated" if the server # answered positively to the request (server answers # "HTTP 200 OK" when file is present) print "Link $_ is validated\n" if <$s>=~/200 OK/; # Close the connection close $s; # and treat the next URL }

You can use the LWP package (launch perl -e 'use LWP' to check if LWP is installed).
With LWP this could be rewritten like this:

use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new; foreach my $url (@ARGV) { my $request = HTTP::Request->new( GET => "$url" ); my $response = $ua->request( $request ); if( $response->is_success ) { print "link $url is ok\n" } }
LWP provide a higher abstraction, you don't need to handle the "low level" socket creation/communication.
Read the documentation for LWP and HTTP::Request for futher details.

Good luck :)

In reply to Re: Can You Explain How to Check a Link for Deadness by choocroot
in thread Can You Explain How to Check a Link for Deadness by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2021-01-27 08:08 GMT
    Find Nodes?
      Voting Booth?