#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
open my $log, '>', 'log.txt'
or die "Can't open the log file!: $!";
find(\&check_data, "./test");
sub check_data {
my $file = $_; #for clarity
return if ! -f $file;
open my $fh, '<', $file
or die "Can't open file $file: $!";
for my $line (<$fh>){
if ($line =~ /^HELLO/){
my @parts = split(/\//, $line);
for my $index (qw(1 3 4)){
if (! $parts[$index] or $parts[$index] =~ /[\s+-]/){
print $log "$file is missing data.\n";
return
}
}
}
}
}
####
$ cat test/hello.pl
adsfasdfasdf
HELLO/asdf/asdf/asdf/asdf/asdf
$ cat test/testing.txt
asdfasdf/dfasdf/12351234132r
HELLO/asdf//////////
####
$ cat log.txt
testing.txt is missing data.