There's too much missing information for a complete and tested solution, and if your 'structure' thingies can be nested, then this probably won't help, but on the basis of what you've posted this seems to come pretty close to your requirements:

#! perl -slw use strict; use Data::Dumper; my $re = qr[ (string|float|float2|float3|float4) \s+ (\w+) \s* (?: < \s* ( [^>]+? ) \s* > \s* )? = \s* ( \S+ ) \s* ; ]x; my $data = do{ local $/; <DATA> }; my %vars; while( $data =~ m[$re]smg ) { my( $type, $name, $structure, $value ) = ( $1, $2, $3, $4 ); $vars{ $name } = { type => $type, value => $value }; if( defined $structure ) { while( $structure =~ m[$re]smg ) { my( $stype, $sname, $svalue ) = ( $1, $2, $4 ); if( my( $prefix, $rest ) = $sname =~ m[([A-Z]+)([A-Z][a-z] ++)] ) { $vars{ $name }{ $prefix }{ $rest } = $svalue; } } } } print Dumper \%vars; __DATA__ float myVarA < float UIMin = 1; float UIMax = 0; float UIStep = .001; string UIWidget = "slider"; > = 0.5f; float myVarB = 1.0; float4 myVarC = {1,0,0,1};

It produces:

C:\test>junk2 $VAR1 = { 'myVarA' => { 'UI' => { 'Step' => '.001', 'Max' => '0', 'Widget' => '"slider"', 'Min' => '1' }, 'value' => '0.5f', 'type' => 'float' }, 'myVarC' => { 'value' => '{1,0,0,1}', 'type' => 'float4' }, 'myVarB' => { 'value' => '1.0', 'type' => 'float' } };

You'd probably need to strip the comments around string initialisers and you don't specify how the initialiser {1,0,0,1} should be treated?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Tricky Parsing Ko'an by BrowserUk
in thread Tricky Parsing Ko'an by jmmistrot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.