On 6/27/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote:
On 6/28/07, Tom Phoenix <[EMAIL PROTECTED]> wrote:
>
> On 6/27/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote:
>
> > I am unable to get a generalised way in which it can extract them as few
> > structures have comments, few does not hav comments etc.
>
> Does the data have some defined grammar, or a definable one at least?
The defined Grammer here is
{
xyz1 abc1; /*Comments*/
xyz2 abc2;
xyz3 abc3[req];
xyz4 abc4[req]; /*Comments*/
};
Here, i have defined different possibility of occurences of the structure
elements. If i could get a regex for extracting xyz1, xyz2, xyz3, xyz4 and
abc1, abc2, abc3[req], abc4[req] would be helpful. Here, the comments are of
no use, i just need to ignore them.
Correct me if I'm wrong, but from your example, it looks like all the
"Dtata Types" are uppercase alphanumerics and underscores, and all the
"variable names" are preceded with at least one space.
I would start with something like the (fragile) following:
my @lines = split /\n/, $string;
while (@lines) {
$_ = shift @lines;
next if /^{/ or /^}/;
my ($type, $name) = /([A-Z_]+)\s*(\S+)/;
if ($name =~ /\[\S+\]/) {
do something with the extra data, or not
}
}
HTH,
-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential
daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org
values of β will give rise to dom!