i believe you are getting an array-ref because you are calling it in list context via the [ ... ] here.

my $myalums = [ $c->model('MyDB::Alumni')->search({}, { rows => 20 }) ] ;


try:

my $myalums_iter = $c->model('MyDB::Alumni')->search({}, { rows => 20 });
    while (my $alum = $myalums_iter->next) { ... }


On Jun 19, 2007, at 11:16 AM, John Goulah wrote:



On 6/19/07, John Napiorkowski <[EMAIL PROTECTED]> wrote:

--- John Goulah <[EMAIL PROTECTED]> wrote:

> If I do something simple like this:
>
>      my $myalums  = [
> $c->model('MyDB::Alumni')->search({}, { rows => 20
> })
> ] ;
>
> and stash it:
>     $c->stash->{alumni} = $myalums;
>
> I am able to iterate in the template like:
>
>    [% FOREACH alum IN alumni -%]
>        id: [% alum.alumni_id %]  <br />
>    [% END -%]
>
>
> But if I try to iterate this in the controller, I
> cannot do something like:
>
>     while (my $alum = $myalums->next) {
>         $c->log->debug("id: ". $alum->alumni_id);
>     }

Because ->next isn't a method on an array reference.
You could try derefing via @$myalumns.


I have tried a few things here.  I can get this to work:


    for my $element (@{$myalums}) {
        $c->log->debug("alum:". $element->alumni_id);
    }


but not :

    while (my $alum = @{$myalums}->next) {
        $c->log->debug("id: ". $alum->alumni_id);
    }

In this case I get:
Can't call method "next" without a package or object reference


I'm assuming I'm just doing something obviously wrong here?

Thanks!
John






_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/ [email protected]/
Dev site: http://dev.catalyst.perl.org/

---
michael reece :: software engineer :: [EMAIL PROTECTED]


_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to