Ok. Just getting back into PERL and probably (or most definitely) making a mountain out of a mole hill.
I'm trying to see if a subdirectory exists, and if not, print the slightly modified path of the missing sub to a file. Sounds simple enough. Well here is my elaborate code. Save the snickering. I know it's nuts. There must be a simpler way.
Directory structure is:
/nas/240/234/2311/VMAIL/1
I need to check that the directory /1 exists. If not, print the 2402342311 to a file.
Any help and tolerance is greatly appreciated
use strict;
my $nas = "/nas";
opendir (NAS, $nas) or die "Can't open $nas: $!";
open OUTFILE, ">bad_accounts" or die $!;
while(my $npa = readdir(NAS)) {
if ($npa =~ /\d{3}/) {
my $path = $nas . "/" . $npa;
print "PATH = '$path' \n";
opendir (NPA, $path) or die "Can't open $path: $!";
while(my $nxx = readdir(NPA)) {
if ($nxx =~ /\d{3}/) {
my $path = $path . "/" . $nxx;
print "PATH = '$path' \n";
opendir (NXX, $path) or die "Can't open $path: $!";
while(my $line = readdir(NXX)) {
if ($line =~ /\d{4}/) {
my $path = $path . "/" . $line;
print "PATH = '$path' \n";
opendir (LINE, $path) or die "Can't open $path: $!";
while(my $vmail = readdir(LINE)) {
if ($vmail == "VMAIL") {
my $path = $path . "/VMAIL";
opendir (VMAIL, $path) or die "Can't open $path: $!";
my $count = grep { ! /^\.{1,2}/ } readdir VMAIL;
if ($count > 2) {
print "COUNT = $count \n";
}
else {
print OUTFILE "BAD ACCT = " . $npa . $nxx . $line . "\n";
print OUTFILE "COUNT = $count \n";
}
}
}
}
}
}
}
}
}
closedir LINE;
closedir NXX;
closedir NPA;
I do get the numbers in a file, but the each number gets printed 3 times :wall: