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.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 } };
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |