#!/usr/bin/env perl
use strict;
use warnings;
#Create the html page(s) for directories
my $indexfile = "html file location";
unlink $indexfile or warn "Could not unlink $indexfile: $!";
unless(open FILE, '>', $indexfile){
die "\nUnable to create $indexfile\n";
}
#Create an array of files listed in each directory
my @array;
my $path = "test";
opendir (my $DIR, $path);
while ( my $entry = readdir $DIR )
{
next unless -f $path . '/' . $entry;
next if $entry eq '.' or $entry eq '..';
push @array, $entry;
}
#Denote data hash for collecting keys from text files
my %data;
#Fill in the files on newly created directory pages
foreach (@array)
{
print FILE "
\n";
print FILE "
",$_;",";
print FILE "
\n";
# Create pages for each file
my $file = "html file location";
unlink $file or warn "Could not unlink $file: $!";
unless(open SUBFILE, '>', $file){
die "\nUnable to create $file\n";
}
#Create an array of PNPs for each test rule
#Open text file in the array
my $pathtxt = $path."/".$_;
open (FH , "+<" , $pathtxt) or die("Can't open $pathtxt: $!");
#Read each line
while (my $line = ){
#Find all instances of specific five character strings
#starts with 4, then 3 more numbers, then a letter)
chomp $line;
if ($line =~ /(4\d{4})/){
#and place in my previously declared data hash
$data{$1}++;
}
}
#Create scaler $k and use it to print my #5-character strings to each file's html page
my $k = (keys %data);
print SUBFILE "\n";
print SUBFILE "
",$k;",";
print SUBFILE "
\n";
}