Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Hash of hashes

by AnomalousMonk (Chancellor)
on Apr 06, 2013 at 00:27 UTC ( #1027234=note: print w/replies, xml ) Need Help??

in reply to Hash of hashes

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 (perldoc perldsc).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027234]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2018-02-21 07:35 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (275 votes). Check out past polls.