Joseph L. Casale wrote:
> I have to search for text strings in files and then do something with the 
> line that matches in one scenario and in another I need to store the contents 
> of the following n lines.
>
> In the first requirement I think I have it beat, but I am lost on the second. 
> I thought I might be able to search for the line I need and store its line 
> number as n, then read the next n+[1...4] lines and store them.
>
> How does one accomplish that, or is there a better approach?
>
> Thanks!
> jlc
>
>   
If you're doing a line by line check anyway and not storing that many
consecutive lines then you could use a flag type of counter that is set
when the line matches and decrements after each read line.

pseudocode:

my $to_store = 4;
my $left = 0;

if (line matches) {
    $left = $to_store;
} elsif ($left > 0) {
    push @store, $line;
    $left--;
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to