dwslovedh has asked for the wisdom of the Perl Monks concerning the following question:
Hi there,
I need to convert non-standard C struct data into standard C struct.
I want change the data to have the format which is like a C struct.
Here is the data, for example:
I want to change the data to:_____________________________________________ mm struct a = 1 b = 3 m1 struct = c = 4 d = 5 __________________________________________
_____________________________________________ mm struct { a = 1; b = 3; m1 struct = { c = 4; d = 5; } } _________________________________________________
This is my 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; }
Now I have the problem with how to add the corresponding "}". Can any one helps? Thanks!
Back to
Seekers of Perl Wisdom