Created
January 21, 2016 19:42
-
-
Save GuiltyDolphin/8cd14a370ac50a88fdd9 to your computer and use it in GitHub Desktop.
Perl script for checking the validity of URLs referenced in Markdown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Check that URLs used in Markdown files actually point somewhere. | |
use strict; | |
use warnings; | |
use LWP::Simple; | |
use List::MoreUtils qw(uniq); | |
use Data::Printer; | |
my @to_check; | |
while (<>) { | |
push @to_check, $_; | |
}; | |
my @urls; | |
foreach my $line (@to_check) { | |
if ($line =~ /\((http[^\) ]*)\)/) { | |
push @urls, $1; | |
}; | |
}; | |
@urls = uniq @urls; | |
@urls = sort @urls; | |
foreach my $url (@urls) { | |
print "Checking URL: $url\n"; | |
unless (head($url)) { | |
print "Failed...\n"; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment