perlquestion
dwslovedh
<p>
Hi there,
<strike>
I need to convert non-standard C struct data into standard C struct.
</strike>
I want change the data to have the format which is like a C struct.
Here is the data, for example:
</p>
<code>
_____________________________________________
mm struct
a = 1
b = 3
m1 struct =
c = 4
d = 5
__________________________________________
</code>
I want to change the data to:
<code>
_____________________________________________
mm struct {
a = 1;
b = 3;
m1 struct = {
c = 4;
d = 5;
}
}
_________________________________________________
</code>
<p>
This is my code:
</p>
<code>
sub change_to_normal {
my $str = shift;
my $find = "(.*)=(.*)";
my $replace = '"$1 = $2;"';
$str =~ s/$find/$replace/eeg; #add ;
my $replace = '"$1 = \{"'; #add {
$str =~ s/(.*)=\s*;/$replace/eeg;
}
</code>
<p>
Now I have the problem with how to add the corresponding "}".
Can any one helps? Thanks!
</p>