Hi stevieb, I've worked on your example but I've run into a snag.

For my testing, I have in my directory only 6 files. 5 of the files have all of the necessary data and the 6th file I have purposely left out data in one of the fields the perl script is supposed to check and another field I have put a dash. So my thinking is that once run, the log will record that only one of the files needs attention.

Below is the perl and I've added line numbers for reference:

1 #!/usr/bin/perl -w 2 3 use warnings; 4 use strict; 5 6 use File::Find; 7 8 open my $log, '>', 'log.txt' 9 or die "Can't open the log file!: $!"; 10 11 find(\&check_data, "./test"); 12 13 sub check_data { 14 15 my $file = $_; #for clarity 16 17 return if ! -f $file; 18 19 open my $fh, '<', $file 20 or die "Can't open file $file: $!"; 21 22 for my $line (<$fh>){ 23 if ($line =~ /^HELLO/){ 24 my @parts = split(/\//, $line); 25 for my $index (qw(1 3 4)){ 26 if (! $parts[$index] or $parts[$index] =~ /[\s+-]/){ 27 print $log "$file is missing data.\n"; 28 return 29 } 30 } 31 } 32 } 33 }

I'm having problems with line 11. What I believe is happening there is that the subrouting check_data is being called with the parameter that is the name of a file called "test". In other words, the ./ is telling perl to look in the present directory for a file called "test" and then run the subrouting on that file.

But what I need to do is have perl look in the directory and check all of the files. I've tried several ways to do this but getting either one of these two errors:

I named the perl script 'stevieb' and I'm running it from the dir in which the files are located.

Error #1

No such file or directory at ./stevieb.pl line 11

Error #2

The second is not an error per se, but in the log.txt all of the files are listed as having missing data which isn't correct

What I'm trying to do is get all of the files into the script instead of just only ready one file, as in your example, but I can't get the syntax of the script to do this. I've tried several ways to do this in line 11:

find(\check_data, ".\*.TXT" ); # look in this dir for all files that end in .TXT Gives error #1

find(\check_data, "./" ); # look in this dir for anything. # Gives error #2

find(\check_data, "./*"); # look in this dir for everything. # Gives error #1

find(\check_data, "."); # look here (as in pwd) Gives error #2

find(\check_data, "/actualNameOfTheDirectory"); # Gives error #2

find(\check_data, ".\/"); # tried escaping the slash thinking that was the problem. Gives error #2

find(\check_data, ".\/*TXT" ); # tried escaping the slash thinking that was the problem. Gives error #1

Long story short, I can't seem to get all the files in the directory to be read without them all producing an error in the log. I've verified that the "good" files are properly formatted.


In reply to Re^2: Perl beginner here, needs a shove in the right direction. by rfromp
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.