[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Ineffektiv perlcode



Hej.

Jeg har nogle cgi-script i perl, hvor jeg genererer nogle websider
ud fra bla. databaseudtræk f.eks. en kundeliste etc.

Imidlertid er min tilgang til det ikke særlig effektiv idet
udførelsestiden som udtryk for mængden af data ikke stiger linært,
men ekponentielt eller sådan noget.

Det jeg gør er, at putte html-formateret data ned i variable og så udskrive
dem til sidst.

----------------------
1 my $html_header = "et eller andet";
2 my $html_body = "";
3 my $html_tail = "et eller andet";
4 my $sth = $dbh->prepare("SELECT SOMETHING"); //bare et MySQL-udtræk
5 $sth->execute();
6 while (my $ref = $sth->fetchrow_arrayref) {
7   $html_body = $html_body.$$ref[0]."<br>";
8 }
9 print STDOUT $html_header.$html_body.$html_tail;
----------------------

Som i kan se i linje 7 kopierer jeg en streng over i sig selv og jo længere
strengen bliver jo længere vil hver iteration tage.

Hvordan kan det gøres bedre, når det er en betingelse, at resultatet
ikke skrives ud før til sidst ?

mvh.

Peter Mærsk-Møller

--
+----------------------------------------------------------+
| Kabel-TV over Internettet   --   http://www.streamtv.dk/ |
+----------------------------------------------------------+


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-10-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *