Other replies are right on the nose, you probably want an array of arrays. However, if there is some reason you can't do that (though I can't imagine why not):
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.'];');
}
}
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:
my %results;
while ($data = $sth1->fetchrow_hashref) {
foreach (keys %$data) {
push $reults{$_}, $$data{$_};
}
}
%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:
foreach (keys %results) {
print "Results for column $_:\n";
foreach (@{$results{$_}}) {
print " $_\n";
}
}
Or something like it.
--
$me = rand($hacker{perl});
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.