Fellow monks, Ok I have been meditating on this for awhile on and can't seem to find enlightenmant. I have been lurking here for years and usually find what I am looking for by searching around the site. This question is more of regexp problem than anything else I suppose. Here is what I am doing. I am trying to parse the following from a file:
//File Snippet Begin// . 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}; . //File Snippet End//
What I would like to do is capture the info in a hash whose keys are the variable names listed above. For example lets say I parsed myVarA this is what I want to capture:
$vars{myVarA}->{type} = "float" $vars{myVarA}->{value} = 0.5 $vars{myVarA}->{ui}->{min}=0 $vars{myVarA}->{ui}->{max}=1 $vars{myVarA}->{ui}->{step}=0.001 $vars{myVarA}->{ui}->{widget}="slider"
The difficulty (at least for me anyway) is capturing the "UI" information "if" it exists. I have tried different regex fencings but am unable to capture both variables with "UI" information and variables without. The real problem is the data-types inside the "UI" description delimited by the "<" and ">" characters. I also tried simplifying things by loading the whole file into a string marking up the data-types and throwing out the whitespace as follows:
#after dumping file to string $file_str=~ s/(float|float2|float3|float4|string)\s+/$+\#/g; $file_str =~ s/\s*//g;
But even in this from I can't come up with a way to split off the UI description because of the data-types inside the carrots. I tried:
$file_str=~s/\<.*(string|float|float2|float3|float4).*\>//g;
as well as:
@lines = split/(float|float2|float3|float4)\#\<.*\>=.*\;/,$file_str;
but no go... I am hoping that the enlightened here can show me the way.. :)

In reply to 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.