You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Gerald Richter <ri...@ecos.de> on 2000/05/16 05:50:43 UTC

Re: FOREACH and TABLES

> How does FOREACH and Tables interact.
>
> I want to use FOREACH with 2 tables inside the loops.
>
> The Table without $row works
> The second table in the look with $row only runs one time.
>

You can nest FOREACH and dynamic tables as often as you like.

I can't tell you more without an example of what you are doing.

Gerald

P.S. Mailinglist address is embperl@perl.apache.org (and _not_
embperl-help@perl.apache.org)

-------------------------------------------------------------
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 925151
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


RE: FOREACH and TABLES

Posted by Gerald Richter <ri...@ecos.de>.
Ruben,
>
> We've seen over time a number of small weird behaviors with FOREACH
> loops and tables.  I though I saw something once about potential
> problems.  This is some test code for a report we are writing.  The top
> half is just testing the returned data structures from the GRADES.pm and
> AUTH.pm modules.  Auth is a home cooked program.  They both inherit DBI
> - a technique we use often:
>

For the first look the code seems to be ok and should run, but because I
can't know what's the data in your arrays, I can't tell what may wrong, or
if it's maybe a bug in Embperl. Very important is to keep in mind, that a
dynamic tables ends, as soon as a undefined value is the last value in a
block that uses $row or $col!

If I should further investigate this problem, I need a small sample, that I
could save to my test box and see what's happening (something without
database access or any custom modules)

Gerald


Re: FOREACH and TABLES

Posted by Ruben I Safir <ru...@sruben.dental.nyu.edu>.
Thanks Gerald -

We've seen over time a number of small weird behaviors with FOREACH
loops and tables.  I though I saw something once about potential
problems.  This is some test code for a report we are writing.  The top
half is just testing the returned data structures from the GRADES.pm and
AUTH.pm modules.  Auth is a home cooked program.  They both inherit DBI
- a technique we use often:

<HTML><HEAD><TITLE>Clinical Performance Report</TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF">
[- use AUTH; -]
[- use GRADES; -]

[- $obj = AUTH->new(\%fdat,'studentgrades', 'auth') -]
[- $obj->sqlpassword('passwd') -]
USER [+ $obj->user +]<P>
PASSWORD [+ $obj->password +]<P>
AUTH [+ $entry = $obj->auth +]<P>
[- $obj2=GRADES->new($fdat{stdno}) -]<P>
OBJ2 [+ $obj2 +]<P>
[+ @recs = $obj2->clinperf +]<P>
[- $recs2 = $obj2->clinperfdept -]<P>
TREE [+ $recs2 +]<P>
[$ foreach $j (sort keys %{$recs2}) $]
Department	[+ $j +] <P>
	[$ foreach $k @$recs2{$j} $]
		[$ foreach $l @$k $]
		[- shift @$l -]
		<TABLE border = 1><TR><TD>[+ $$l[$col] +]</TD></TR></TABLE>
		[$ endforeach $]
	[$ endforeach $]
[$ endforeach $]

REC [+ $recs[0][0][0] +]<P>
SIZE [+ @{$recs[0]} +]<P>

[$ foreach $i (0.. @{$recs[0]}) $]
	DEPT [+ $recs[0][$i][0] +]<P>
	[- $dept{$recs[0][$i][0]} = '' -]
[$ endforeach $]

[$ foreach $key (keys(%dept)) $]
	KEYS [+ $key +]<P>
[$ endforeach $]
[$ if $entry $]


####tabling starts here###########
###Just a  Header##########
<HR>
<TABLE BGCOLOR="#EEEEEE" BORDERCOLOR="BLACK"  BORDER="1" CELLPADDING=4
ALIGN="CENTER" width="80%" >
	<TR>
		<TD>
		<H3 ALIGN="CENTER">New York University College of Dentistry</H3>
		<H4 ALIGN="CENTER">ACADEMIC RECORD OF CLINICAL PERFORMANCE</H4>
		<B><SMALL>Print Date [+ localtime +]</SMALL>
&#160&#160&#160&#160&#160&#160&#160&#160&#160&#160&#160Mannequins&#160Included</B>
		<P><CENTER>Begining Date - Ending Date</CENTER>

		</TD>
	</TR>
</TABLE>	
####################Test Table to view Data
#############################
<TABLE border=1>
	<TR>
		<TD>
		[+ $recs[0][$row][$col] +]
		</TD>
	</TR>
</TABLE>
###########################################################################
#############Final Format broken down by each
department####################

[- @departments = sort keys(%$recs2) -]

<P><FONT COLOR="RED">DEPARTMENT</FONT> [+ $departments[1] +]<P>
<H4>[+ $fdat{'stdno'} +] [+ $obj2->name($fdat{'stdno'}) +]</H4>

##########Start Foreach
####################################################

[$ foreach $tmp @departments $]
###Unneeded just trying different things ####### [- $newdept = $tmp -]

####This table repeats as it
should#########################################

<TABLE BGCOLOR="#EEEEEE" BORDERCOLOR="BLACK" BORDER=1 CELLPADDING=4
ALIGN="CENTER" width="95%">
	<TR>
		<TD>
			<SMALL>
			<B>
			[+ $newdept +]
&#160&#160&#160&#160&#160&#160&#160&#160&#160&#160Total Points:
Num&#160&#160&#160&#160&#160Total Deductions: Num
&#160&#160&#160&#160&#160Net Points:	Num
			</B>
			</SMALL>
		</TD>
	</TR>
</TABLE> 
#############This table only runs only once for the first
department##########

<TABLE BGCOLOR="#FFFFFF" border=1>
	<TR>
		<TH><SMALL>Line</SMALL></TH>
		<TH><SMALL>Patient</SMALL></TH>
		<TH><SMALL>Date</SMALL></TH>
		<TH><SMALL>ADA-1</SMALL></TH>
		<TH><SMALL>Procedure</SMALL></TH>
		<TH><SMALL>Tooth-1</SMALL></TH>
		<TH><SMALL>Surf</SMALL></TH>
		<TH><SMALL>Status</SMALL></TH>
		<TH><SMALL>Gr</SMALL></TH>
		<TH><SMALL>WP</SMALL></TH>
		<TH><SMALL>ADA-2</SMALL></TH>
		<TH><SMALL>Tooth-2</SMALL></TH>
		<TH><SMALL>Surf</SMALL></TH>
		<TH><SMALL>Status</SMALL></TH>
		<TH><SMALL>Gr</SMALL></TH>
		<TH><SMALL>WP</SMALL></TH>
		<TH><SMALL>Inf</SMALL></TH>
		<TH><SMALL>IC</SMALL></TH>
		<TH><SMALL>Concerns</SMALL></TH>
		<TH><SMALL>Instructor</SMALL></TH>
	</TR>
	<TR>
		<TD>[+ $row +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][0] +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][1] +][- $adacode =
$$recs2{$newdept}[$row + 1][2] -]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][2] +]</TD>
		<TD>[+ $obj2->ada_translate($adacode) +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][3] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][4] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][5] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][6] or ' ' +]</TD>
		<TD>Calculate</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][7] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][8] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][9] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][10] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][11] or ' ' +]</TD>
		<TD>Calculate</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][12] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][13] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][14] or ' ' +]</TD>
		<TD>[+ $$recs2{$newdept}[$row + 1][15] or ' ' +]</TD>
	</TR>	
</TABLE>	


[$ endforeach $]

###########For Each ends################################################
[$ else $]
<h1>Sorry - Your not validated</h1>
[$ endif $]
</BODY>
</HTML>
__________________________________________________________________________

The url of this is:
http://sruben.dental.nyu.edu/embperl2/clinperf.html

and the entry form is 
http://sruben.dental.nyu.edu/studs/studentgrade.html

I'll send a password to you privately if you need it.


Also - we get this behavior where if we FOREACH through an array, and
then loop through it again. that we end up with an undefined value on
the front.  This is also seen in this program in the following subcode
on the top:

<HTML><HEAD><TITLE>Clinical Performance Report</TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF">
[- use AUTH; -]
[- use GRADES; -]

[- $obj = AUTH->new(\%fdat,'studentgrades', 'auth') -]
[- $obj->sqlpassword('passwd') -]
USER [+ $obj->user +]<P>
PASSWORD [+ $obj->password +]<P>
AUTH [+ $entry = $obj->auth +]<P>
[- $obj2=GRADES->new($fdat{stdno}) -]<P>
OBJ2 [+ $obj2 +]<P>
[+ @recs = $obj2->clinperf +]<P>
[- $recs2 = $obj2->clinperfdept -]<P>
TREE [+ $recs2 +]<P>
[$ foreach $j (sort keys %{$recs2}) $]
Department	[+ $j +] <P>
	[$ foreach $k @$recs2{$j} $]
		[$ foreach $l @$k $]
####HERE	[- shift @$l -]
		<TABLE border = 1><TR><TD>[+ $$l[$col] +]</TD></TR></TABLE>
		[$ endforeach $]
	[$ endforeach $]
[$ endforeach $]


This behavior is continual - and always takes place under this condition
across
boxes and diferent programs


Gerald Richter wrote:
> 
> > How does FOREACH and Tables interact.
> >
> > I want to use FOREACH with 2 tables inside the loops.
> >
> > The Table without $row works
> > The second table in the look with $row only runs one time.
> >
> 
> You can nest FOREACH and dynamic tables as often as you like.
> 
> I can't tell you more without an example of what you are doing.
> 
> Gerald
> 
> P.S. Mailinglist address is embperl@perl.apache.org (and _not_
> embperl-help@perl.apache.org)
> 
> -------------------------------------------------------------
> 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 925151
> 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

-- 
Ruben I Safir

ruben@sruben.dental.nyu.edu
ruben@wynn.noSppam.com

Perl Notes:
http://www.wynn.com/jewish/perl_course

http://www.brooklynonline.com
Manager of Intranet Development NYU College of Dentistry
Resume:  http://www.wynn.com/jewish/resume.html