Skip to content

Instantly share code, notes, and snippets.

@GuiltyDolphin
Created January 21, 2016 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuiltyDolphin/8cd14a370ac50a88fdd9 to your computer and use it in GitHub Desktop.
Save GuiltyDolphin/8cd14a370ac50a88fdd9 to your computer and use it in GitHub Desktop.
Perl script for checking the validity of URLs referenced in Markdown.
#!/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