in reply to Change the data to have the format which is like a C struct.
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 |
In Section
Seekers of Perl Wisdom