I'm trying to read a config file that will have something like the following information:

Product1 property=value property2=value Product2 feature1 property=value property2=value feature2 property3=value Product3 feature1 property=value property2=value

I need to read this file in and display it in a Perl Tk project. I'm just having a hard time figuring out how to keep track of the features because not all products have features.

@file = <IN>; foreach(@file){ if (/^TSS/){ # All product begin with TSS # Its a product }elseif ($_ =~ /=/){ # get the property and value using split }else{ # Its a feature??? } } # Should I use something like: $hash{$product}{$feature}{$property} = "value"; # or $hash{$product}{$property} = "value"; $hash{$product}{feature} = "feature name"; # if the feature key is her +e, there is a feature. # but how do I keep properties listed after the correct feature!

Obviously some sort of Hash should do the trick but having hard time visualizing it. Any help is appreciated.


In reply to Reading Install type config file into hash by tmurnane

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.