On 6/5/07, Gavin Spomer <[EMAIL PROTECTED]> 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