develooper Front page | perl.beginners | Postings from May 2007

Regarding files

Thread Next
From:
Dharshana Eswaran
Date:
May 20, 2007 21:37
Subject:
Regarding files
Message ID:
9f91e0840705202137q11ce8b82v2af20b58444a980d@mail.gmail.com
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 and once i get the string,

I need to read few lines which occurs before the string. For eg:

typedef union
{
    TYPE_T type;
   MODE_T mode;
} CHANNEL_INFO_T;

Here, I grep for CHANNEL_INFO_T, once i get that, i need to read the
elements defined in the union or structure.


I have written a code but i am unable to achieve what i wanted.

Can anyone guide me in this?

Thanks and Regards,
Dharshana

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About