Обсуждение: Re[2]: [INTERFACES] Perl Interface
Afternoon, intriguing... however, how do I go to the next row? I tried a variation earlier that looked
like: while (@row = $result->fetchrow) { $string = join("\|",@row); } $result = $conn->getResult;
I've also tried : while ($result = $conn->getResult) { while (@row = $result->fetchrow) {
$string = join("\|",@row); } push(@set,$string); } The goal is to get
multiplerows into a single array. The answer is probally very simple. Thx, -Rob
______________________________ Reply Separator _________________________________
Subject: Re: [INTERFACES] Perl Interface
Author: James Olin Oden <joden@lee.k12.nc.us> at INTERNET
Date: 06/22/1999 2:24 PM
Just change that $ret to @ret, and it will return the entire row.
After that your code becomes something like: $query = "Select
username,password,knickname,emailaddy,forward,ip,date from temp"; $conn = Pg::connectdb("dbname=$dbname"); $result =
$conn->exec($query); while (@row = $result->fetchrow) { @row = join("|", @row); }
robert_hiltibidal_at_cms08405@ccmailgw.state.il.us wrote:
>
> Afternoon,
>
> intriguing... however, how do I go to the next row? I tried a
> variation earlier that looked like:
>
> while (@row = $result->fetchrow) {
> $string = join("\|",@row);
> push(@set,$string);
> }
> $result = $conn->getResult;
>
>
> I've also tried :
>
> while ($result = $conn->getResult) {
> while (@row = $result->fetchrow) {
> $string = join("\|",@row);
> }
> push(@set,$string);
> }
>
>
> The goal is to get multiple rows into a single array. The answer is
> probally very simple.
>
Looks like you caught my "|" error (-; Seriously, I though the
following should do it:
while (@row = $result->fetchrow) { $string = join("\|",@row); push @set, ($string); }
If though you wanted to put them in a multidimensional array (well
really a list of references to lists then you would do something like:
while (@row = $result->fetchrow) { push @set, (@row); }
and then you would reference each element like this:
$set[$i][$j]
or:
$set[$i]->[$j]
depending on your mood.
...james
Sorry I did not catch up with the original question; I believe things
you discuss here are better answered by reading "man perldata" or "man
perlref". But let me make a few comments, anyway.
> Looks like you caught my "|" error (-; Seriously, I though the
> following should do it:
>
> while (@row = $result->fetchrow) {
> $string = join("\|",@row);
> push @set, ($string);
> }
>
> If though you wanted to put them in a multidimensional array (well
> really a list of references to lists then you would do something like:
>
> while (@row = $result->fetchrow) {
> push @set, (@row);
> }
{push @set, ($string)} is the same as {push @set, $string} or {push (@set, $string)}
{push @set, (@row); is the same as {push @set, @row} or {push @set, $row[0], $row[1], ...}
There is no such thing as multidimensional array in perl.
One can simulate multidimensional arrays by using arrays of
references. You probably wanted to say,
push @set, [@row];
or
push @set, \@row;
>
> and then you would reference each element like this:
>
> $set[$i][$j]
>
> or:
>
> $set[$i]->[$j]
>
> depending on your mood.
which would now now be true.
--Gene