Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have a series of text files I would like to open and verify they either contain a full record or not. records are comma delimited as follows example.. of 1 record. 4/22/2009 1:36:02 PM,29.281263,23.429273,4.420066,29.219497,2.847088,11.055522,0.159151,AAR my current code so far which reads in directories and list of files I also have a small script which shows a single files content with labels, I would like to modify this file so that it checks for a full record or not, if not it should skip the line and do the next or possibly trash the line.
<code> opendir(DIR, "c:\\mlx\\") || die "can't opendir: $!"; my @list = grep { $_ ne '.' && $_ ne '..'&& $_ ne 'copy.pl' } @list=readdir(DIR); foreach my $name (@list) { $path="c:\\mlx\\$_"; shift @list; print $name, "\n"; opendir(DIR, "$path\\$name"); my @files=grep {$_ ne '.' && $_ ne '..'} @files=readdir(DIR); foreach $file(@files){ print "filename is ", $file, " \n"; print "and I am in directory ", $name, " \n"; } } example of echoing contents of file.. open (FILE, '04-22-2009.txt'); while (<FILE>) { chomp; ($timeoftest, $login, $searchload, $searchresults, $searchdetails,$add +listing,$editlisting,$logout,$sitecode) = split(","); print "time of test: $timeoftest\n"; print "login: $login\n"; print "searchload: $searchload\n"; print "searchresults: $searchresults\n"; print "searchdetails: $searchdetails\n"; print "addlisting: $addlisting\n"; print "editlisting: $editlisting\n"; print "logout: $logout\n"; print "sitecode: $sitecode\n"; print "---------\n"; } close (FILE); exit;
I tried using the sample provided by lostjimmy but I don't totally understand what its doing now.. all it does is give me some file names and the following output here is the code now.. and my output is below it. I would like for it to go through all directories and open all the files testing each and reporting if one does not contain the proper number of fields.
#use strict; #use warnings; opendir(DIR, "c:\\mlx\\") || die "can't opendir: $!"; my @list = grep { $_ ne '.' && $_ ne '..'&& $_ ne 'copy.pl' } readdir( +DIR); foreach my $name (@list) { $path="c:\\mlx\\$_"; shift @list; print $name, "\n"; opendir(DIR, "$path\\$name"); my @files=grep {$_ ne '.' && $_ ne '..'}readdir(DIR); foreach $file(@files){ print "filename is ", $file, " \n"; print "and I am in directory ", $name, " \n"; chdir $name; print "I am in directory $name"; open (FILE, '$file')|| die "Cannot open file $file"; while (<FILE>) { chomp; ($timeoftest, $login, $searchload, $searchresults, $searchdetails,$add +listing,$editlisting,$logout,$sitecode) = split(","); print "time of test: $timeoftest\n"; print "login: $login\n"; print "searchload: $searchload\n"; print "searchresults: $searchresults\n"; print "searchdetails: $searchdetails\n"; print "addlisting: $addlisting\n"; print "editlisting: $editlisting\n"; print "logout: $logout\n"; print "sitecode: $sitecode\n"; print "---------\n"; } close (FILE); exit; } }
output..
C:\>perl 2.pl 03-27-2009.txt 04-02-2009.txt 04-07-2009.txt 04-09-2009.txt 04-13-2009.txt 04-15-2009.txt 04-17-2009.txt 04-21-2009.txt 04-23-2009.txt AAR filename is 04-16-2009.txt and I am in directory AAR Cannot open file 04-16-2009.txt at 2.pl line 22. I am in directory AAR

In reply to testing files for valid content by grashoper

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2024-04-18 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found