-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoveBadLicenses.pl
69 lines (56 loc) · 1.56 KB
/
removeBadLicenses.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl -w
# Example code from Chapter 1 of /Perl and LWP/ by Sean M. Burke
# http://www.oreilly.com/catalog/perllwp/
#require 5;
use strict;
use warnings;
use File::Copy;
if (scalar(@ARGV) != 1) {
print "Usage: removeBadLicenses.pl StateFolder\n";
exit;
}
my $stateFolder = $ARGV[0];
my $i;
my $file;
our $fullFilename;
my $totalNum = 845;
for ($i = 1; $i <= $totalNum; $i++) {
my @files;
my $directory = "$stateFolder/licenses/$i";
opendir(DIR, $directory) or die "Could not open directory $directory $!";
@files = grep(/.htm$/, readdir(DIR));
closedir(DIR);
print "Handling folder licenses/$i\n";
my %validFiles;
my $inFile = "$stateFolder/VAHealthSearch/results" . threeDigit($i) . ".htm";
open(IN, "<$inFile") or die "Could not open search page $inFile $!";
my @lines = <IN>;
close(IN);
# Read all the lines from file $i, then get each license found therein.
my $j;
for ($j = 0; $j < scalar(@lines); $j++) {
if ($lines[$j] =~ m/license_no=(\d+)/) {
my $filename = "license$1.htm";
$validFiles{$filename} = 1;
}
}
foreach $file (@files) {
if (!defined($validFiles{$file})) {
move($directory . "/" . $file, "$stateFolder/licenses/NowMissing/$file");
print "Removed $directory/$file\n";
}
}
}
print "done! Ta Da \n";
sub threeDigit
{
my $num = $_[0];
if ($num < 10) {
return "00" . $num;
} elsif ($num < 100) {
return "0" . $num;
} else {
return $num;
}
}