in reply to declaring arrays dynamically
That would generate @field1, @field2,... @fieldn for the width of your row. Using an array of arrays or even a hash would work better. A hash method:while (@data = $sth1->fetchrow_array()) { for (my $field = 0; $field <= $#data ; $field++) { my $var_cnt = $field+1; #needed for cat in next line to work eval('push @field'.$var_cnt.', $data['.$field.'];'); } }
%results is now a hash of arrays. $results{degree} contains an array of all values for the field "degree" in your table. These can be extracted by:my %results; while ($data = $sth1->fetchrow_hashref) { foreach (keys %$data) { push $reults{$_}, $$data{$_}; } }
Or something like it.foreach (keys %results) { print "Results for column $_:\n"; foreach (@{$results{$_}}) { print " $_\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: declaring arrays dynamically
by ikegami (Patriarch) on Sep 14, 2004 at 18:58 UTC |