in reply to Small Doubt Regarding Select Staement in DB
i want to get the ouput using "return" function and using "array of arrays".my @row; while (@row = $sth1->fetchrow_array) { print "@row \n"; }
Hmmmm.... you are nearly done. Inside the loop, you already have the data as an array. Though you can't exactly have "array of array", you can at least have either "array of arrayreference" or "reference to array of arrayreference", depending on your likings (or maybe depending on the calling context). If you define your result array initially as
you can successively push references to the rows into it, like this:my @resultarray;
Then you can do one of these:push @resultarray,\@row;
Although I personally use the latter type of return occasionally in my own code, I know that this usage is somewhat questionable, and at least needs to be documented well.return @resultarray; # returns list when called in list context return \@resultarray; # returns reference return wantarray ? @resultarray : \@resultarray; # adapt to calling co +ntext
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Small Doubt Regarding Select Staement in DB
by koti688 (Sexton) on Nov 03, 2008 at 12:03 UTC |