Hi, Thank you for all the responses. I must admit that I never realised that what I was getting was not the last value but the number of elements in the array. Anyway, in the course of my experimentation, I did make some half hearted attempts with '$c->stash->{myoptions} = [EMAIL PROTECTED];' yesterday, but instead of the options, I was getting a list of 'myleave::Model::myleavedb::txn_mdl=HASH(some_number) in the tt2 template. When I tried again today after your replies, I got the same result. Here is my code:
sub cancel : Local { my ($self,$c) = @_; my @options = $c->model('myleavedb::txn_mdl')->search({emp_no => $c->user->emp_no},{columns => [qw/lv_id/]}); $c->stash->{myoptions} = [EMAIL PROTECTED]; $c->stash->{template} = 'leavedata/cancel2_frm.tt2'; } Then I added a foreach loop as under and I got the expected results in the tt2 template. I also had to declare @new_options at the top. sub cancel : Local { my ($self,$c,@new_options) = @_; my @options = $c->model('myleavedb::txn_mdl')->search({emp_no => $c->user->emp_no},{columns => [qw/lv_id/]}); foreach my $option(@options) { push (@new_options,$option->lv_id) } $c->stash->{myoptions} = [EMAIL PROTECTED]; $c->stash->{template} = 'leavedata/cancel2_frm.tt2'; } I don't understand in what way @options and @new_options are different from each other, but in a bumbling manner I have made the code work. What is the preferred way of writing this bit of code? jagdish eashwar > ---------------------------------------------------------------------- > > Message: 1 > Date: Sun, 11 Nov 2007 21:58:04 +0530 > From: "jagdish eashwar" <[EMAIL PROTECTED]> > Subject: [Catalyst] difficulty in assigning an array to a stash > To: catalyst@lists.scsys.co.uk > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1 > > Hi, > I am trying to retrieve into an array a list of values from a column > in a table using dbic and have it displayed in a drop down list in a > tt2 template. I am able to do the retrieval part, but the tt2 template > is displaying only the last value from the array. With further > experimentation, I found that if I explicitly assign an array to a > stash ( like '$c->stash->{myoptions} = [qw/1 2 3 4 5 6 7/];' ), I am > getting all the 7 values in the tt2 template drop down. But if I > define the array first and then assign it to the stash, ( like 'my > @options = qw/1 2 3 4 5 6 7/; $c->stash->{myoptions} = @options;) I am > getting only the last value in the tt2 template. How can I get all the > values in the array into the stash without having to do it explicitly? > > > > ------------------------------ > > Message: 2 > Date: Sun, 11 Nov 2007 11:37:47 -0500 > From: Andy Grundman <[EMAIL PROTECTED]> > Subject: Re: [Catalyst] difficulty in assigning an array to a stash > To: The elegant MVC web framework <catalyst@lists.scsys.co.uk> > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=US-ASCII; format=flowed > > > On Nov 11, 2007, at 11:28 AM, jagdish eashwar wrote: > > > Hi, > > I am trying to retrieve into an array a list of values from a column > > in a table using dbic and have it displayed in a drop down list in a > > tt2 template. I am able to do the retrieval part, but the tt2 template > > is displaying only the last value from the array. With further > > experimentation, I found that if I explicitly assign an array to a > > stash ( like '$c->stash->{myoptions} = [qw/1 2 3 4 5 6 7/];' ), I am > > getting all the 7 values in the tt2 template drop down. But if I > > define the array first and then assign it to the stash, ( like 'my > > @options = qw/1 2 3 4 5 6 7/; $c->stash->{myoptions} = @options;) I am > > getting only the last value in the tt2 template. How can I get all the > > values in the array into the stash without having to do it explicitly? > > $c->stash->{myoptions} = [EMAIL PROTECTED]; > > > > ------------------------------ > > Message: 3 > Date: Sun, 11 Nov 2007 16:40:31 +0000 > From: "Mark Smith" <[EMAIL PROTECTED]> > Subject: Re: [Catalyst] difficulty in assigning an array to a stash > To: "The elegant MVC web framework" <catalyst@lists.scsys.co.uk> > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1 > > > But if I > > define the array first and then assign it to the stash, ( like 'my > > @options = qw/1 2 3 4 5 6 7/; $c->stash->{myoptions} = @options;) I am > > getting only the last value in the tt2 template. How can I get all the > > values in the array into the stash without having to do it explicitly? > > That's because you're stuffing an array in a scalar. Or trying. Do this: > > my @options = qw/1 2 3 4 5 6 7/; > $c->stash->{myoptions} = [EMAIL PROTECTED]; > > Or, for a literal translation of your first code: > > my $options = [ qw/1 2 3 4 5 6 7/ ]; > $c->stash->{myoptions} = $options; > > Note the differences. > > While you're at it, try "perldoc perlreftut" and "perldoc perlref" for > more information on references. > > Good luck. > > > -- > Mark Smith / xb95 > [EMAIL PROTECTED] > > > > ------------------------------ > > Message: 4 > Date: Sun, 11 Nov 2007 17:41:54 +0100 > From: Lars Balker Rasmussen <[EMAIL PROTECTED]> > Subject: Re: [Catalyst] difficulty in assigning an array to a stash > To: The elegant MVC web framework <catalyst@lists.scsys.co.uk> > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=us-ascii > > On Sun, Nov 11, 2007 at 09:58:04PM +0530, jagdish eashwar wrote: > > Hi, > > I am trying to retrieve into an array a list of values from a column > > in a table using dbic and have it displayed in a drop down list in a > > tt2 template. I am able to do the retrieval part, but the tt2 template > > is displaying only the last value from the array. With further > > experimentation, I found that if I explicitly assign an array to a > > stash ( like '$c->stash->{myoptions} = [qw/1 2 3 4 5 6 7/];' ), I am > > getting all the 7 values in the tt2 template drop down. But if I > > define the array first and then assign it to the stash, ( like 'my > > @options = qw/1 2 3 4 5 6 7/; $c->stash->{myoptions} = @options;) I am > > getting only the last value in the tt2 template. How can I get all the > > values in the array into the stash without having to do it explicitly? > > $c->stash->{myoptions} = [EMAIL PROTECTED]; > > perldoc perlreftut > -- > Lars Balker Rasmussen Consult::Perl > > > > ------------------------------ > > Message: 5 > Date: Sun, 11 Nov 2007 20:52:04 +0100 > From: "A. Pagaltzis" <[EMAIL PROTECTED]> > Subject: [Catalyst] Re: difficulty in assigning an array to a stash > To: catalyst@lists.scsys.co.uk > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=us-ascii > > * Mark Smith <[EMAIL PROTECTED]> [2007-11-11 19:15]: > > While you're at it, try "perldoc perlreftut" and "perldoc > > perlref" for more information on references. > > Also `perldoc perllol` and `perldoc perldsc`. > > Regards, > -- > Aristotle Pagaltzis // <http://plasmasturm.org/> > > > > ------------------------------ > > Message: 6 > Date: Mon, 12 Nov 2007 10:12:08 +0100 > From: Felix Antonius Wilhelm Ostmann <[EMAIL PROTECTED]> > Subject: Re: [Catalyst] difficulty in assigning an array to a stash > To: The elegant MVC web framework <catalyst@lists.scsys.co.uk> > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > jagdish eashwar schrieb: > > > I am > > getting only the last value in the tt2 template. > > no, you count the array and save it into the scalar. your problem: count > and last element are the same ;) > > use [EMAIL PROTECTED] or [EMAIL PROTECTED] to save the reference. > > > > > How can I get all the > > values in the array into the stash without having to do it explicitly? > > > > _______________________________________________ > > List: Catalyst@lists.scsys.co.uk > > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > > Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ > > Dev site: http://dev.catalyst.perl.org/ > > > > > > > > > -- > Mit freundlichen Grüßen > > Felix Antonius Wilhelm Ostmann > -------------------------------------------------- > Websuche Search Technology GmbH & Co. KG > Martinistraße 3 - D-49080 Osnabrück - Germany > Tel.: +49 541 40666-0 - Fax: +49 541 40666-22 > Email: [EMAIL PROTECTED] - Website: www.websuche.de > -------------------------------------------------- > AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310 > Komplementärin: Websuche Search Technology > Verwaltungs GmbH - AG Osnabrück - HRB 200359 > Geschäftsführer: Diplom Kaufmann Martin Steinkamp > -------------------------------------------------- > > > > > ------------------------------ > > > Message: 8 > Date: Mon, 12 Nov 2007 11:02:07 +0000 > From: Carl Johnstone <[EMAIL PROTECTED]> > Subject: Re: [Catalyst] difficulty in assigning an array to a stash > To: The elegant MVC web framework <catalyst@lists.scsys.co.uk> > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > jagdish eashwar wrote: > > I am getting only the last value in the tt2 template. > You're actually getting the number of items in the list, because that's > what you get when you turn a list into a single value. > > Carl > > > > > ------------------------------ > > _______________________________________________ > Catalyst mailing list > Catalyst@lists.scsys.co.uk > http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > > > End of Catalyst Digest, Vol 33, Issue 23 > **************************************** > _______________________________________________ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/