perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gavin Spomer <spom...@cwu.EDU>
Subject Re: Object Arrays & Dynamic Tables
Date Fri, 22 Jun 2007 16:03:54 GMT
Hi Angus,

Just wanted to shoot you a quick email to let you know I wasn't ignoring you and your reply
was appreciated. Just got busy with work! :O

Makes sense too. :)

- Gavin

>>> Angus Lees <guslees@gmail.com> 06/10/07 2:22 PM >>>
On 6/5/07, Gavin Spomer <spomerg@cwu.edu> wrote:
>
> Hi Folks,
>
> I have an array of "facet" objects called @facets. A "facet" object has a
> method called facet_name. I would like to output this using dynamic tables,
> instead of having to do an Embperl foreach loop. The following Embperl
> foreach loop works:
>
>    <table>
>    [$ foreach $facet (@facets) $]
>       <tr>
>          <td>[+ $facet->facet_name +]</td>
>       </tr>
>    [$ endforeach $]
>    </table>
>
> However when I try using an Embperl dynamic table (as desired) like the
> following:
>
>    <table>
>       <tr>
>          <td>[+ $facets[$row]->facet_name +]</td>
>       </tr>
>    </table>
>
> I get an error:
>
>    [1381]ERR: 24: Error in Perl code: Can't call method "facet_name" on an
> undefined value at /usr/local/mylibrary/index.epl line 17.
>
> Oddly enough, the following works (using a literal value of zero instead
> of $row):
>
>    <table>
>       <tr>
>          <td>[+ $facets[0]->facet_name +]</td>
>       </tr>
>    </table>
>
> And also this works too, even though it isn't the output I'm looking for:
> (It's not calling facet_name)
>
>    <table>
>       <tr>
>          <td>[+ $facets[$row] +]</td>
>       </tr>
>    </table>
>
> What am I doing wrong? It seems to me like something funky is going on
> with $row.


Thats how $row works.  It keeps repeating the expression until it evaluates
to undef.  This works great for $array[$row], but in your case the last row
is undef->facet_name which gives that error.

Try [+ $facets[$row] and $facets[$row]->facet_name +]  or else switch to
(possibly nested) array/hash structures rather than method calls.

-- 
- Gus


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


Mime
View raw message