I would be thinking along the following lines:
use Data::Dumper; my %hash; my $client = "client1"; $hash{$client}{fieldA} = 12234; #from another query: $hash{$client}{fieldC} = 9876; print Dumper \%hash; __END__ $VAR1 = { 'client1' => { 'fieldA' => 12234, 'fieldC' => 9876 } };
To generate your output, make an array to specify the column order: my @order = qw (fieldC fieldB fieldA); Then when processing each client, cycle through the order array, if value exists for that client, put it, if not then put "" or whatever. I am just thinking that a hash representation will work out better for accumulating the data, then make the 2D array for output after the data has been collected rather than keeping each row's columns straight during the data accumulation phase.

Update: I mentioned before that there is more than one way to retrieve the data, one of those ways is as a hash. That might be of use to you...you have a bit of reading to do!

use Data::Dumper; my %hash; my $client = "client1"; $hash{$client}{fieldA} = 12234; #from another query: $hash{$client}{fieldC} = 9876; my @order = qw (fieldC fieldB fieldA); foreach my $client (keys %hash) { print "$client"; foreach my $field (@order) { if (exists $hash{$client}{$field}) { print "\t$hash{$client}{$field}"; } else { print "\tno_value"; } } print "\n"; } #prints: client1 9876 no_value 12234

In reply to Re^7: Help with MySQL SELECT into multidimensional array by Marshall
in thread Help with MySQL SELECT into multidimensional array by btongeorge

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.