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?
Something like this may be what you require: my $n; my $contents; while ( <FILE> ) { if ( /one scenario/ ) { # do something } if ( /in another/ ) { $contents = ''; # Clear out the variable $n = $.; } if ( $n ) { $contents .= $_; # accumulate lines $n = 0 if $. == $n + 4; } } John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/