Hello,
Since you are having the whole file in an array.
1. Keep an index to specify the current line read
2. Once you found the desired string, you have the index also. So
you can
decrement the index and get the lines.
$inex = 0;
foreach $line (@lines) {
$index++;
if($line =~ m/
On 05/20/2007 11:37 PM, Dharshana Eswaran wrote:
Hi All,
The below code helps in reading a file in reverse:
use strict;
use warning;
open( FILE, $file_to_reverse )
or die( Can't open file file_to_reverse: $! );
@lines = reverse FILE;
foreach $line (@lines) {
# do something with $line
}
Thank you all..
But i dont want to use any perl modules in the code. I am trying to get a
logic without any help from the additional modules.
Thanks and Regards,
Dharshana
On 5/21/07, Mumia W. [EMAIL PROTECTED] wrote:
On 05/20/2007 11:37 PM, Dharshana Eswaran wrote:
Hi All,
The below code
Dharshana Eswaran schreef:
i am trying to grep for a string in the file and once i get the
string, I need to read few lines which occurs before the string.
The classic (state machine) approach is to start storing strings from
the start marker, so typedef union here, and discard the stored
Keeping the classic (state machine) approach in mid, i tried writing a logic
for the same
But i am not able to retrieve the lines accurately,
Can you please help me with a small piece of code for the same logic which
you mentioned?
On 5/21/07, Dr.Ruud [EMAIL PROTECTED] wrote:
Dharshana
Hi,
Dharshana Eswaran [EMAIL PROTECTED] wrote:
Keeping the classic (state machine) approach in mid, i tried
writing a logic for the same
But i am not able to retrieve the lines accurately,
Can you please help me with a small piece of code for the
same logic which you mentioned?
This
Dharshana Eswaran schreef:
You really shouldn't quote text that is no longer relevant, such as
signatures and mailing list tails.
Ruud:
Dharshana Eswaran:
i am trying to grep for a string in the file and once i get the
string, I need to read few lines which occurs before the string.
The
Hi All,
The below code helps in reading a file in reverse:
use strict;
use warning;
open( FILE, $file_to_reverse )
or die( Can't open file file_to_reverse: $! );
@lines = reverse FILE;
foreach $line (@lines) {
# do something with $line
}
But i am trying to grep for a string in the file