It looks like you might want to wind up with a program having a hash-of-hashes for which the following statements were true (given the example data):
    my %my_data;
    ...
    if ($my_data{'tt.exe'}{'ABC'}{'start'} == 10) { print qq{it's true! \n}; }
    ...
    if ($my_data{'xx.exe'}{'def'}{'finish'} == 3) { print qq{also true! \n}; }

How would one produce a hash having an element for which the expression
    $my_data{'tt.exe'}{'ABC'}{'start'} == 10
was true? The simple statement
    $my_data{'tt.exe'}{'ABC'}{'start'} = 10;
does the trick (note = assignment in place of the == numeric equality operator).

A more generic program fragment might look something like
    my %my_data;
    ...
    my $record = get_record_from_raw_data();
    ...
    my $name   = get_executable_name_from($record);
    my $quota  = get_quota_from($record);
    my $start  = get_start_from($record);
    my $finish = get_finish_from($record);
    $my_data{$name}{$quota}{'start'}  = $start;
    $my_data{$name}{$quota}{'finish'} = $finish;
    ...

How would one extract a record from your data? That's very dependent on the exact definition of the structure of your data, which you don't give. However, your example suggests that your data is a set of multi-line records and that the executable-name field of each record is always the first field (i.e., first line) in the record, and real data in this field always starts at the very first column of the line (i.e., the line has no leading whitespace); this could be used to recognize the beginning of a record if the data file were processed line-by-line rather than by extracting each record in one gulp as implied in the generic pseudo-code above. All subsequent fields seem to begin with some kind of leading whitespace, and the first field (i.e., the first line) after the executable-name field, the redundant quota-start-finish header name field, can always be ignored.

If the data file were processed on a line-by-line basis, a regex could be used to recognize the beginning field of each record and extract the executable name from the field, and split could be used on each subsequent field of the record (after skipping the redundant field) to extract the quota-start-finish sub-field data from each field. (Of course, all this ignores important data validation considerations.)

And then you do something with all your extracted data, and there's your program!

See also the Perl Data Structures Cookbook (perldocperldsc).


In reply to Re: Hash of hashes by AnomalousMonk
in thread Hash of hashes by gibsonca

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.