Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

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


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?


Comment on Re: Convert Non-standard C struct data to standard C struct
Select or Download Code
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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031086]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-08-02 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (53 votes), past polls