Skip to content

Instantly share code, notes, and snippets.

@kisom
Last active September 15, 2015 04:21
Show Gist options
  • Save kisom/00a6ca79ffd62c35b4ab to your computer and use it in GitHub Desktop.
Save kisom/00a6ca79ffd62c35b4ab to your computer and use it in GitHub Desktop.
scanning elvi
~/code/perl
(0) <tessier:kyle> $ perl scan-elvi.pl
w3link doesn't match.
l1sp doesn't match.
w3rdf doesn't match.
w3html doesn't match.
worldwidescience doesn't match.
searx doesn't match.
w3css doesn't match.
f5 doesn't match.
bookfinder doesn't match.
Makefile doesn't match.
126 elvi found.
116 elvi matched the pattern.
~/code/perl
(0) <tessier:kyle> $
#!/usr/bin/env perl
my $elvidir = "$ENV{'HOME'}/code/shell/surfraw/elvi/";
sub check_elvi {
my ($elvi) = @_;
$elvi = $elvidir . $elvi;
open(my $ELVI, $elvi) || die "Failed to open $elvi.\n";
while (<$ELVI>) {
chomp($_);
if ($_ =~ /^# elvis: [a-zA-Z]+\t+--/) {
close($ELVI);
return 1;
}
}
close($ELVI);
return 0;
}
sub scan_elvi {
my $elvi_count = 0;
my $match_count = 0;
opendir(my $DIRH, $elvidir) || die "Can't open $elvldir\n";
while (my $elvi = readdir($DIRH)) {
next if ($elvi =~ /\.{1,2}/);
$elvi_count++;
if (&check_elvi($elvi) == 1) {
$match_count++;
} else {
print "$elvi doesn't match.\n";
}
}
closedir($DIRH);
print "$elvi_count elvi found.\n";
print "$match_count elvi matched the pattern.\n";
}
&scan_elvi();
~/code/shell/surfraw/elvi
(0) <tessier:kyle> $ awk 'NR == 3' w3link| xxd
0000000: 2320 656c 7669 733a 2077 336c 696e 6b09 # elvis: w3link.
0000010: 092d 2d20 4368 6563 6b20 7765 6220 7061 .-- Check web pa
0000020: 6765 206c 696e 6b73 2077 6974 6820 7468 ge links with th
0000030: 6520 7733 6320 6c69 6e6b 6368 6563 6b65 e w3c linkchecke
0000040: 7220 2876 616c 6964 6174 6f72 2e77 332e r (validator.w3.
0000050: 6f72 672f 6368 6563 6b6c 696e 6b29 0a org/checklink).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment