Hi Jenny1990, it's hard to follow what you are trying to do. Can you please post a stripped-down version of your code?

You probably need to build up a hash data structure. You could either do a complex SQL query on several tables, or you could build up your data structure as you read the rows from each table.

Your data might look like this after you've built it:

my $measurements = { 'MeasurementA' => { 1 => { 'Date' => 'DateA', 'Value' => '1A', }, }, 'MeasurementB' => { 1 => { 'Date' => 'DateB', 'Value' => '3A', }, 2 => { 'Date' => 'DateD', 'Value' => '2A', }, 3 => { 'Date' => 'DateE', 'Value' => '5A', }, }, 'MeasurementC' => { 1 => { 'Date' => 'DateC', 'Value' => '3A', }, }, };

And then you can use it to produce your report:

foreach my $measurement ( sort keys %{ $measurements } ) { print "Measurement: $measurement\n"; foreach my $try ( sort keys %{ $measurements->{ $measurement } } ) { + print " Try: $try\n"; print " Date: $measurements->{ $measurement }->{ $try }->{'Dat +e'}\n"; print " Value: $measurements->{ $measurement }->{ $try }->{'Val +ue'}\n"; } }

Outputs:

Measurement: MeasurementA Try: 1 Date: DateA Value: 1A Measurement: MeasurementB Try: 1 Date: DateB Value: 3A Try: 2 Date: DateD Value: 2A Try: 3 Date: DateE Value: 5A Measurement: MeasurementC Try: 1 Date: DateC Value: 3A

Or,

foreach my $measurement ( sort keys %{ $measurements } ) { print "$measurement -- "; foreach my $try ( sort keys %{ $measurements->{ $measurement } } ) { + print "$measurements->{ $measurement }->{ $try }->{'Date'}: $measu +rements->{ $measurement }->{ $try }->{'Value'} "; last if $try == scalar keys %{ $measurements->{ $measurement } }; print " -- "; } print "\n"; }

Outputs:

MeasurementA -- DateA: 1A MeasurementB -- DateB: 3A -- DateD: 2A -- DateE: 5A MeasurementC -- DateC: 3A

But first you'll have to build your data structure.

The way forward always starts with a minimal test.

In reply to Re: Sorting measurements by 1nickt
in thread Sorting measurements by Jenny1990

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.