Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: Embperl

Object Arrays & Dynamic Tables

 

 

ModPerl embperl RSS feed   Index | Next | Previous | View Threaded


spomerg at cwu

Jun 5, 2007, 1:30 PM

Post #1 of 4 (1677 views)
Permalink
Object Arrays & Dynamic Tables

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.

Gavin Spomer
Systems Programmer
Brooks Library
Central Washington University

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe [at] perl
For additional commands, e-mail: embperl-help [at] perl


richter at ecos

Jun 6, 2007, 11:21 PM

Post #2 of 4 (1573 views)
Permalink
RE: Object Arrays & Dynamic Tables [In reply to]

Hi,

>
> 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.
>

Embperl iterates through the array until the expression inside the [+ +]
is undef.

So in your case it iterates past the end of the array, which cause the
$facets[$row] to be undef and therefor you will see the error.

You can write

[+ eval { $facets[$row]->facet_name } +]

, but this will also disable real error messages

So the real solution would be

[+ $facets[$row]?$facets[$row]->facet_name:undef +]

In such cases I prefer to use the foreach loop...

Gerald



** Virus checked by BB-5000 Mailfilter **

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe [at] perl
For additional commands, e-mail: embperl-help [at] perl


guslees at gmail

Jun 10, 2007, 2:22 PM

Post #3 of 4 (1547 views)
Permalink
Re: Object Arrays & Dynamic Tables [In reply to]

On 6/5/07, Gavin Spomer <spomerg [at] cwu> 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


spomerg at cwu

Jun 22, 2007, 9:03 AM

Post #4 of 4 (1522 views)
Permalink
Re: Object Arrays & Dynamic Tables [In reply to]

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 [at] gmail> 06/10/07 2:22 PM >>>
On 6/5/07, Gavin Spomer <spomerg [at] cwu> 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 [at] perl
For additional commands, e-mail: embperl-help [at] perl

ModPerl embperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.