### Re: Convert Non-standard C struct data to standard C struct

by hdb (Monsignor)
 on Apr 28, 2013 at 15:17 UTC ( #1031086=note: print w/replies, xml ) Need Help??

For the simple example above, this here works

```use strict;
use warnings;

my \$struct = <<STRUCT;
mm struct
a = 1
b = 3
m1 struct =
c = 4
d = 5
STRUCT

sub change_to_normal {
my @lines = split /\n/, shift;
my \$str;
my @indent;
for my \$line (@lines) {
if( \$line =~ /struct/ ) {
\$line =~ /^(\s*)/;
push @indent, length( \$1 );
\$line =~ s/=//g;
\$str .= \$line."= {\n";
} elsif( \$line =~ /.*=.*/ ) {
\$str .= \$line.";\n";
} else {
\$str .= \$line."\n";
}
}
while( @indent ) {
my \$ind = pop @indent;
\$str .= " "x\$ind."}\n";
}
return \$str;
}

print change_to_normal( \$struct );

but I assume that you can have more complex cases as well? For example:

```mm struct
a = 1
b = 3
m1 struct =
c = 4
d = 5
e = 7

what would you expect?

Replies are listed 'Best First'.
Re^2: Convert Non-standard C struct data to standard C struct
by dwslovedh (Novice) on Apr 29, 2013 at 01:42 UTC

Yes, the data I have is a little similar with C struct. I would expect:

```mm struct {
a = 1;
b = 3;
m1 struct = {
c = 4;
d = 5;
}
e = 7;
}

Create A New User
Node Status?
node history
Node Type: note [id://1031086]
help
Chatterbox?
 [Discipulus]: good morning folks!

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-10-17 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My fridge is mostly full of:

Results (220 votes). Check out past polls.

Notices?