Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How do I skip reading files with missing data?

by vinoth.ree (Monsignor)
on Nov 19, 2015 at 18:29 UTC ( [id://1148141]=note: print w/replies, xml ) Need Help??


in reply to How do I skip reading files further with missing data?

Use the directory functions: opendir, closedir and readdir.

opendir DIR, $dir or die "cannot open dir $dir: $!"; my @filenames= readdir DIR; closedir DIR;
This will read the list of file names into the @filenames array.

You can use the scalar Range Operators

open my $fh, "<", $file or die $!; while (<$fh>) { print if /+=======+=======+============+============+============+ +/ .. /+-------+-------+------------+------------+------------+/; }
OR

use flag like below,

foreach my $file (@filenames) my $filepath = "/FILEPATH/$file"; open my $fh, "<",$filepath or die("could not open log file: $!"); my $in = 0; while(<$fh>) { $in = 1 if /+=======+=======+============+============+=========== +=+/; print if($in); $in = 0 if /+-------+-------+------------+------------+----------- +-+/; }
Note: Not Tested

All is well. I learn by answering your questions...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1148141]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found