GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: parsing c file using perl script
Operating System - HP-UX
1846627
Members
1980
Online
110256
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2005 04:59 PM
05-26-2005 04:59 PM
parsing c file using perl script
Hi,
I am newbie to perl script programming.
I have given a c file, that has two arrays like
const static array1
{1, 0, 0, 0, 0, 0},
{1, 1, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0},
};
const static array2= {
{"104804",339},
{"106546",999},
{"106547",999}
};
I want to know how to extract the only first array using perl script
I have used the follwing regular expression to parse the elements like this.
I have my file contents in $str.
@struct= $str=~m/$structure\[\].*};/g;
@struct_lines = $struct[0]=~m/[ ]*{[ -:{,\t\"_A-Za-z0-9.]*}/g;
But when I print the $struct[0], it is extracting all the array elements.
Could anybody help me in extracting only the first array?
Regards,
Poornima.
I am newbie to perl script programming.
I have given a c file, that has two arrays like
const static array1
{1, 0, 0, 0, 0, 0},
{1, 1, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0},
};
const static array2= {
{"104804",339},
{"106546",999},
{"106547",999}
};
I want to know how to extract the only first array using perl script
I have used the follwing regular expression to parse the elements like this.
I have my file contents in $str.
@struct= $str=~m/$structure\[\].*};/g;
@struct_lines = $struct[0]=~m/[ ]*{[ -:{,\t\"_A-Za-z0-9.]*}/g;
But when I print the $struct[0], it is extracting all the array elements.
Could anybody help me in extracting only the first array?
Regards,
Poornima.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2005 05:42 PM
05-26-2005 05:42 PM
Re: parsing c file using perl script
@struct= $str =~ m/const static[^;]*};/g;
Something like this will leave you will array1 in $struct[0], array2 in $struct[1] etc.
Something like this will leave you will array1 in $struct[0], array2 in $struct[1] etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2005 06:44 PM
05-26-2005 06:44 PM
Re: parsing c file using perl script
First of all, you have the file content in $str, but that includes the newlines. Newlines are *not* matched by . in regular expressions, unless you add /s modifier.
Secondly, (i hope you typoed) the first defenition is illegal: it misses '= {' on the declaration line. But assuming it was there in the first place,
my %arr;
while ($str =~ m/\bconst\s+static\s+(\w+)\s*=\s*{(.*?)};/gs) {
$arr{$1} = $2;
}
will place array1 in $arr{array1}, array2 in $arr{2} etc
Enjoy, Have FUN! H.Merijn
Secondly, (i hope you typoed) the first defenition is illegal: it misses '= {' on the declaration line. But assuming it was there in the first place,
my %arr;
while ($str =~ m/\bconst\s+static\s+(\w+)\s*=\s*{(.*?)};/gs) {
$arr{$1} = $2;
}
will place array1 in $arr{array1}, array2 in $arr{2} etc
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2005 07:29 PM
05-26-2005 07:29 PM
Re: parsing c file using perl script
Thanks guys,
That solved my problem.
-Poornima.
That solved my problem.
-Poornima.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP