Dharshana Eswaran wrote:
Hi All,

I am trying to extract few strings from a text file. The pattern of the text
stored in the file is as follows:

#define MNSS_FACILITY_IND_ID (TF_MNSS_MESSAGE_CATEGORY + 0x01) /* @LOG
MNSS_MESSAGE_T */


I need to extract MNSS_FACILITY_IND_ID, TF_MNSS_MESSAGE_CATEGORY + 0x01 and
MNSS_MESSAGE_T.

I tried

next unless /#define\s+(\w+)\s+\(([^)]+)\s+\/[EMAIL PROTECTED](\w+)\*\//;

my $name = $1;
my ($base, $offset) = $2 =~ /\w+/g;
my $Struct = $3;


Darshana,

You were missing a literal closing paren after the offset and some spaces right at the end. Here's the fix:

next unless /#define\s+(\w+)\s+\(([^)]+)\)\s+\/[EMAIL PROTECTED](\w+)\s+\*\//;

And here is a possible alternative. I'm not sure what your other lines to match look like, so your mileage may vary.

my ($name, $base, $offset, $struct) =
   $line =~ m!#define\s+(\w+)\s+\((\w+).*?(\w+)\).*?\s+(\w+)!;

Hope this helps,
-m




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


Reply via email to