You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Christian Frantsen <ic...@guruland.org> on 2002/02/24 19:14:23 UTC

Problem with foreach

Could someone explain to me why this works...

[-
  foreach $row (@$result) {
    print OUT "$row->[1]";
  }
-]

.. and this doesn't?

[$ foreach $row @$result $]
    [+ $row->[1] +]
[$ endsub $]


@$result is the result of a database query using DBI with
selectall_arraryref()


/Christian


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Problem with foreach

Posted by Gerald Richter <ri...@ecos.de>.
>
> @$result is the result of a database query using DBI with
> selectall_arraryref()
>

Normaly both should work. Which version of Embperl do you using? Does it
change anything if you make ( ) around the @$result in the second example?

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Problem with foreach

Posted by Christian Frantsen <ic...@guruland.org>.
GAH!

I should have seen that to :)

Well now it works, thanks alot for the help!

/Christian

----- Original Message -----
From: "Gerald Richter" <ri...@ecos.de>
To: "Christian Frantsen" <ic...@guruland.org>; <em...@perl.apache.org>
Sent: Monday, February 25, 2002 2:33 PM
Subject: Re: Problem with foreach


> >
> > If i try this...
> >
> > [$ foreach $row @$result $]
> >   [+ $row +]
> > [$ endforech $]
> >
> > ... the only output is a '0', there should be an ARRAY ref there.
> >
>
> I should have seen this after your first mail...
>
> $row is special inside a Embperl page. It's always the row counter and
> because you are not in a table it's always zero. Use another name, e.g.
$rec
> then it will work
>
> Gerald
>
> -------------------------------------------------------------
> Gerald Richter    ecos electronic communication services gmbh
> Internetconnect * Webserver/-design/-datenbanken * Consulting
>
> Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
> E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
> WWW:        http://www.ecos.de      Fax:      +49 6133 925152
> -------------------------------------------------------------
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Problem with foreach

Posted by Gerald Richter <ri...@ecos.de>.
>
> If i try this...
>
> [$ foreach $row @$result $]
>   [+ $row +]
> [$ endforech $]
>
> ... the only output is a '0', there should be an ARRAY ref there.
>

I should have seen this after your first mail...

$row is special inside a Embperl page. It's always the row counter and
because you are not in a table it's always zero. Use another name, e.g. $rec
then it will work

Gerald

-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Problem with foreach

Posted by Christian Frantsen <ic...@guruland.org>.
I tried both with brackets and without, the same result :(

If i try this...

[$ foreach $row @$result $]
  [+ $row +]
[$ endforech $]

... the only output is a '0', there should be an ARRAY ref there.


btw, I'm using on embperl 1.3.4

/Christian


----- Original Message ----- 
From: "Gavin Carr" <ga...@openfusion.com.au>
To: "Christian Frantsen" <ic...@guruland.org>
Sent: Sunday, February 24, 2002 9:33 PM
Subject: Re: Problem with foreach


> On Sun, Feb 24, 2002 at 07:14:23PM +0100, Christian Frantsen wrote:
> > Could someone explain to me why this works...
> > 
> > [-
> >   foreach $row (@$result) {
> >     print OUT "$row->[1]";
> >   }
> > -]
> > 
> > .. and this doesn't?
> > 
> > [$ foreach $row @$result $]
> >     [+ $row->[1] +]
> > [$ endsub $]
> 
> You're missing brackets round the @$result aren't you? 
> 
>   [$ foreach $row (@$result) $]
> 
> Otherwise the second one should work fine.
> 
> Cheers,
> Gavin
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org