Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by vinoth.ree (Monsignor)
on Nov 19, 2015 at 18:29 UTC ( #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
Node Status?
node history
Node Type: note [id://1148141]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2020-05-26 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (150 votes). Check out past polls.

    Notices?