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

We use jQuery Autocomplete in our existing interface. A perl script does a database query and sends back the data as follows
print $q->header(); foreach my $row ( @$Results ) { print "$row->{'DOC_SUB_TYPE'}|$row->{'DESCRIPTION'}\n"; }
When I move CGI::Application, I've tried leaving this in which returns the results plus an additional header at the bottom of the JS scroll list. If I comment out the print header line it doesn't work at all. What can I do to have one correct header returned from CGI::Application. I appreciate any feedback.

Replies are listed 'Best First'.
Re: CGI to CGI::Application, headers problem
by Anonymous Monk on Jan 20, 2011 at 11:00 UTC
      Thank you. I've removed the print headers, and altered my print statement to return rather than print the data, but i'm just getting the first return value. Any ides?
        Well, you don't simply swap return for print, because as you've discovered, return exits a subroutine (see perlintro)

        The CGI::Application documentation shows you the correct way to do it

        ... my $output = ""; foreach my $row ( @$Results ) { $output .= "$row->{'DOC_SUB_TYPE'}|$row->{'DESCRIPTION'}\n"; } return $output; ...