Quicksilver has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I've set up a scrolling list which calls the names of various items from a database. I had thought that I'd written the code so that the sorted list will appear as a list but it comes out as a row (that is I get foo bar baz instead of
foo
bar
baz).
This is the first form that I've created from scratch (most of the other stuff is pure maintenance) so I'd be grateful if someone could let me know what I've done incorrectly.
#!c:\perl\bin\perl.exe use strict; use warnings; use CGI; use DBI; #calling the service overview tables my $q= new CGI; print $q->header(); print $q->start_html(-title=>'service metrics'); print qq[<form method="post"action="/cgi-bin/service.pl" name="metric" +>]; #code to create the scroll down box which selects from the db my $db = DBI->connect(foo, bar, baz {RaiseError => 1, AutoCommit => 1}); my $sth = $db->prepare("SELECT Name FROM service_metrics"); $sth->execute; my @data; while (my @result = $sth->fetchrow_array) { push @data,$result[0]; } print $q->scrolling_list(-name=>"metrics", -value=>"@data"); $sth->finish; $db->disconnect(); print $q->submit(-value=>"Choose"); print qq[</form>];
Many thanks for your help, Iain

Replies are listed 'Best First'.
Re: Getting a row rather than an expected scrolling list
by spatterson (Pilgrim) on Aug 16, 2007 at 10:55 UTC
    scrolling_list in common with many of the CGI methods takes an arrayref as an argument, not a simple array.

    so print $q->scrolling_list( -name=> metrics, -value=> [ @data ] ); should work


    just another cpan module author
Re: Getting a row rather than an expected scrolling list
by moritz (Cardinal) on Aug 16, 2007 at 10:57 UTC
    You are interpolating the array into a string instead of using a reference to it.

    Use $q->scrolling_list(-name=>"metrics", -value=>\@data); instead.

Re: Getting a row rather than an expected scrolling list
by FunkyMonk (Bishop) on Aug 16, 2007 at 10:56 UTC