Maybe you mean something like this, where you are adding a value to the @right_array listing:
push (@right_array, $row[1]);
Or, something like this where you are adding the row to the @right_array:
push (@right_array, \@row);
Probably what you mean by
@right_array is that you want to specify which array to put the stuff into, correct?
sub fill_array(\@)
{
my ($right_array) = @_;
# ...
while (my @row = $sth->fetchrow_array())
{
push (@$right_array, \@row);
}
# ...
}
# As a test
fill_array (@name);
This is achived by using references. Instead of knowing exactly which array you are going to be using, you have a handle to it (
$right_array versus
@right_array) that you can use like an array with the proper prefix (
@$right_array).
If you choose to put the entire row in there, then what you have is a multi-dimensional array. To get out data, you can either get a whole row (array) or a single entry:
my @row = @{$name[1]}; # Row 1
my $row_item_1 = $name[1][1]; # Row 1 column 1
Maybe this is what you had in mind?
Don't forget that array numbering starts at 0, so the first element is actually
$row[0]. Call it the "zeroth" row, if you will.
Something to consider apart from this code is to use some of the specialized
DBI calls, such as
selectall_arrayref and
selectcol_arrayref. For the latter, in particular, there is no point in fetching a whole row of data when all you want is a single column.
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.