Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by hdb (Monsignor)
on Apr 28, 2013 at 15:17 UTC ( [id://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?

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; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-29 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found