Usually we don't write full-blown scripts if the Seeker of Perl Wisdom doesn't post any example code, but I put something together here that should get you started.

I'm not sure if glob would be faster, as I did not test it, so you can play around.

This code looks at all files located in the directory specified as the second argument to find() (recursively). If it's a file, it opens it, reads it line by line, and if it has the keyword (HELLO) at the start of line, it checks the line fields 1, 3 and 4 (after being split() on a forward slash) to ensure they are not empty. If the file contains a line starting with 'HELLO' but has at least one line without all the fields with data, it'll log to a file and continue on.

You'll need to research how to print the directory path with the file in the log (if you need it), sort out your indexing, replace your keyword etc

#!/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 } } } } }

Example files:

$ cat test/hello.pl adsfasdfasdf HELLO/asdf/asdf/asdf/asdf/asdf $ cat test/testing.txt asdfasdf/dfasdf/12351234132r HELLO/asdf//////////

Output:

$ cat log.txt testing.txt is missing data.

-stevieb

EDIT: Added check for hyphen in line elems


In reply to Re: Perl beginner here, needs a shove in the right direction. by stevieb
in thread Perl beginner here, needs a shove in the right direction. by rfromp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.