Advertisement

06.17.2004 at 08:30AM PDT, ID: 21029046
[x]
Attachment Details

Loading and array with data while parsing a file line by line!

Asked by Troyh in Perl Programming Language

Tags: array, loading, file, line

I Have a very large file (80M) which I am parsing line by line with the code below.

$file = "datalog.txt";
open(INPUT, $file) || die("Could not open file - $file!");
    while($line=<INPUT>){
        chomp $line;
       
        "Search for a string and do something"

        }
close(INPUT);

Now when I come across a particular string I would like to load the line containing the string and the next 20 lines into an array for processing. I'm not quite sure how to do this? Any suggestions or alternative ways to do this?
I have tried "Slurping" the whole file into an array at the beginning but this takes forever to run!!!

Thanks,
- TroyStart Free Trial
 
Loading Advertisement...
 
[+][-]06.17.2004 at 09:02AM PDT, ID: 11336062

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: array, loading, file, line
Sign Up Now!
Solution Provided By: jmcg
Participating Experts: 2
Solution Grade: B
 
 
[+][-]06.23.2004 at 02:46PM PDT, ID: 11383779

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.24.2004 at 12:50AM PDT, ID: 11386430

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32