FAQ
Hi,
I may ask the same old question, but just could get it. So please help me to get it done. All I want is looping through the record set for example: if I want to loop through a column, I can use this:

my @lname;
########################
my $column = $c->model("myDB::Author")->get_column('last_name');
while(my $name = $column->next){
$lname[$i] = $name;
$i = $i + 1;
}
-----
but if I try:
my $recordset = [$c->model('myDB::Books')->search( authorid => "${authorid}" )];
while(my $name = $recordset->next){
$lname[$i] = $name->lname;
$fname[$i] = $name->fname;
$i = $i + 1;
}

I get error:

Can't call method "next" without a package or object reference

I know this is the error of declaration of the array and the method used to call, but did not see something similar in the docs.

Thank you




---------------------------------
Looking for earth-friendly autos?
Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070212/0bba0980/attachment.htm

Search Discussions

  • Jonathan Rockway at Feb 12, 2007 at 8:21 pm

    Will Smith writes:
    my $recordset = [$c->model('myDB::Books')->search( authorid =>
    "${authorid}" )];
    while(my $name = $recordset->next){
    $lname[$i] = $name->lname;
    $fname[$i] = $name->fname;
    $i = $i + 1;
    }

    Wrong list, but here's a hint... arrays aren't iterators. Get rid of
    the []s.

    --
    package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
    $,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
    ";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
  • Will Smith at Feb 12, 2007 at 8:31 pm
    you're right. The $recordset is just an arrayref, that's why the ->next does not work. That's why I would like to ask, what will work in this case?
    the [] brackets are for another things - I need to assign each value of the recordset to another set of arrays....

    thanks

    Jonathan Rockway wrote: Will Smith writes:
    my $recordset = [$c->model('myDB::Books')->search( authorid =>
    "${authorid}" )];
    while(my $name = $recordset->next){
    $lname[$i] = $name->lname;
    $fname[$i] = $name->fname;
    $i = $i + 1;
    }

    Wrong list, but here's a hint... arrays aren't iterators. Get rid of
    the []s.

    --
    package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
    $,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
    ";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/



    ---------------------------------
    Don't pick lemons.
    See all the new 2007 cars at Yahoo! Autos.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070212/0816a148/attachment.htm
  • Bogdan Lucaciu at Feb 12, 2007 at 8:27 pm

    On Monday 12 February 2007 22:15, Will Smith wrote:
    ?my $recordset = [$c->model('myDB::Books')->search( authorid =>
    "${authorid}" )]; while(my $name = $recordset->next){
    what's whith the square brackets [] ?
    $recordset is not an object, just an arrayref, so ->next doesn't work.

    --
    Bogdan Lucaciu
    http://www.wiz.ro
  • Boris Ćeranić at Feb 12, 2007 at 8:28 pm

    On 12/02/07, Will Smith wrote:
    Hi,
    I may ask the same old question, but just could get it. So please help me
    to get it done. All I want is looping through the record set for example: if
    I want to loop through a column, I can use this:

    my @lname;
    ########################
    my $column =
    $c->model("myDB::Author")->get_column('last_name');
    while(my $name = $column->next){
    $lname[$i] = $name;
    $i = $i + 1;
    }
    -----
    but if I try:
    my $recordset = [$c->model('myDB::Books')->search(
    authorid => "${authorid}" )];
    while(my $name = $recordset->next){
    $lname[$i] = $name->lname;
    $fname[$i] = $name->fname;
    $i = $i + 1;
    }
    ...

    Thank you
    You should have placed $recordset in foreach, like this:

    my $recordset = [ something that returns list in list context ];

    foreach my $name ( @$recordset ) {
    ...
    }
  • Will Smith at Feb 12, 2007 at 8:56 pm
    thank you for your help. That's exactly what I want to do.

    regards

    Boris ?erani? wrote: On 12/02/07, Will Smith wrote:
    Hi,
    I may ask the same old question, but just could get it. So please help me
    to get it done. All I want is looping through the record set for example: if
    I want to loop through a column, I can use this:

    my @lname;
    ########################
    my $column =
    $c->model("myDB::Author")->get_column('last_name');
    while(my $name = $column->next){
    $lname[$i] = $name;
    $i = $i + 1;
    }
    -----
    but if I try:
    my $recordset = [$c->model('myDB::Books')->search(
    authorid => "${authorid}" )];
    while(my $name = $recordset->next){
    $lname[$i] = $name->lname;
    $fname[$i] = $name->fname;
    $i = $i + 1;
    }
    ...

    Thank you
    You should have placed $recordset in foreach, like this:

    my $recordset = [ something that returns list in list context ];

    foreach my $name ( @$recordset ) {
    ...
    }

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/



    ---------------------------------
    TV dinner still cooling?
    Check out "Tonight's Picks" on Yahoo! TV.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070212/9f48183a/attachment.htm
  • Michael Fuchs at Feb 12, 2007 at 8:30 pm
    I think it's because you called search in list context. That way you end
    up with an array of rows. Try it without the square brackets to get the
    resultset.

    mike


    Will Smith schrieb:
    Hi,
    I may ask the same old question, but just could get it. So please help
    me to get it done. All I want is looping through the record set for
    example: if I want to loop through a column, I can use this:

    my @lname;
    ########################
    my $column = $c->model("myDB::Author")->get_column('last_name');
    while(my $name = $column->next){
    $lname[$i] = $name;
    $i = $i + 1;
    }
    -----
    but if I try:
    my $recordset = [$c->model('myDB::Books')->search( authorid =>
    "${authorid}" )];
    while(my $name = $recordset->next){
    $lname[$i] = $name->lname;
    $fname[$i] = $name->fname;
    $i = $i + 1;
    }

    I get error:
    Can't call method "next" without a package or object reference
    I know this is the error of declaration of the array and the method used to call, but did not see something similar in the docs.

    Thank you
    ------------------------------------------------------------------------
    Looking for earth-friendly autos?
    Browse Top Cars by "Green Rating"
    <http://autos.yahoo.com/green_center/;_ylc=X3oDMTE4MGw4Z2hlBF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDZ3JlZW5jZW50ZXI->
    at Yahoo! Autos' Green Center.
    ------------------------------------------------------------------------

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
  • Aristotle Pagaltzis at Feb 14, 2007 at 5:42 am

    * Will Smith [2007-02-12 21:25]:
    my $column = $c->model("myDB::Author")->get_column('last_name');
    while(my $name = $column->next){
    $lname[$i] = $name;
    $i = $i + 1;
    }
    Ugh. Use `push`; this isn?t C.

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>
  • Ian Docherty at Feb 14, 2007 at 2:00 pm

    A. Pagaltzis wrote:
    * Will Smith [2007-02-12 21:25]:
    my $column = $c->model("myDB::Author")->get_column('last_name');
    while(my $name = $column->next){
    $lname[$i] = $name;
    $i = $i + 1;
    }
    Ugh. Use `push`; this isn?t C.

    Regards,
    Or 'map'
  • Aristotle Pagaltzis at Feb 14, 2007 at 5:21 pm
    Hi Ian,

    * Ian Docherty [2007-02-14 16:40]:
    A. Pagaltzis wrote:
    * Will Smith [2007-02-12 21:25]:
    my $column = $c->model("myDB::Author")->get_column('last_name');
    while(my $name = $column->next){
    $lname[$i] = $name;
    $i = $i + 1;
    }
    Ugh. Use `push`; this isn?t C.
    Or 'map'
    That won?t work here, since there?s no list to process, just an
    iterator. (I always thought List::Util should supply `unfold`?)

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>
  • Mark Zealey at Feb 14, 2007 at 6:09 pm
    You could of course do somethnig like:

    push @lname => $c->model('myDB::Author')->get_column('last_name')->all;

    tmtowtdi

    Mark
    On Wednesday 14 February 2007 5:21 pm, A. Pagaltzis wrote:
    Hi Ian,

    * Ian Docherty [2007-02-14 16:40]:
    A. Pagaltzis wrote:
    * Will Smith [2007-02-12 21:25]:
    my $column = $c->model("myDB::Author")->get_column('last_name');
    while(my $name = $column->next){
    $lname[$i] = $name;
    $i = $i + 1;
    }
    Ugh. Use `push`; this isn?t C.
    Or 'map'
    That won?t work here, since there?s no list to process, just an
    iterator. (I always thought List::Util should supply `unfold`?)

    Regards,
  • Jason Kohles at Feb 14, 2007 at 7:06 pm

    On Feb 14, 2007, at 12:21 PM, A. Pagaltzis wrote:

    Hi Ian,

    * Ian Docherty [2007-02-14 16:40]:
    A. Pagaltzis wrote:
    * Will Smith [2007-02-12 21:25]:
    my $column = $c->model("myDB::Author")->get_column('last_name');
    while(my $name = $column->next){
    $lname[$i] = $name;
    $i = $i + 1;
    }
    Ugh. Use `push`; this isn�t C.
    Or 'map'
    That won�t work here, since there�s no list to process, just an
    iterator. (I always thought List::Util should supply `unfold`�)
    Of course map, push, and everything else is kind of pointless anyway...

    my @name = $c->model( 'myDB::Author' )->get_column( 'last_name' )->all;

    --
    Jason Kohles
    email@jasonkohles.com
    http://www.jasonkohles.com/
    "A witty saying proves nothing." -- Voltaire


    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070214/623f642c/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedFeb 12, '07 at 8:15p
activeFeb 14, '07 at 7:06p
posts12
users9
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase