Re: How to manipulate rows in returned resultset

Sam Tregar <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
On Mon, 13 Mar 2006, Kapoor, Nishikant wrote:

> Is there a way I can continue to use the 'single' assignment, and
> still achieve this objective?

You seem to have the right idea here:

> #BUT, if I need to bold the 'search text', I need to iterate through the loop
> my @loopData=();
> foreach my $rec (@{$data}) {
>  my %loopRow;
>  $rec->{title} =~ s/(\b$searchText\b)/<b>$1<\/b>/ig;
>  $loopRow{title} = $rec->{title};
>  push @loopData, \%loopRow;
> }
> $template->param(myLoopVar => \@loopData);

If you're dying to do it in one statement I suppose you could do:

   $template->param(myLoopVar =>
     [ map { $_->{title} =~ s!\b($searchText)\b!<b>$1</b>!ig;
             $_ } @$data ]);

I don't exactly consider that an improvement, personally.

-sam


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.