home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 1997 / CT_SW_97.ISO / pc / software / entwickl / win95 / plsei306.exe / aspSamples / fibfxn.asp < prev    next >
Text File  |  1997-03-22  |  2KB  |  94 lines

  1. <%@ LANGUAGE = PerlScript%>
  2. <HTML>
  3. <HEAD>
  4. <!-- 
  5.     Copyright (c) 1996, Microsoft Corporation.  All rights reserved.
  6.     Developed by ActiveWare Internet Corp., http://www.ActiveWare.com
  7. -->
  8. <TITLE> Fibonacci numbers through 17 </TITLE>
  9. </HEAD>
  10. <BODY> <BODY BGCOLOR=#FFFFFF>
  11. <!-- 
  12.     ActiveWare PerlScript sample 
  13.     PerlScript:  The coolest way to program custom web solutions. 
  14. -->
  15.  
  16. <!-- Masthead -->
  17. <TABLE CELLPADDING=3 BORDER=0 CELLSPACING=0>
  18. <TR VALIGN=TOP ><TD WIDTH=400>
  19. <A NAME="TOP"><IMG SRC="PSBWlogo.gif" WIDTH=400 HEIGHT=48 ALT="ActiveWare PerlScript" BORDER=0></A><P>
  20. </TD></TR></TABLE>
  21.  
  22. <FONT SIZE=3>    
  23.  
  24. Date/time:    <%
  25.     ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
  26.     $thisday=(Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)[$wday];
  27.     $thismon=(January,February,March,April,May,June,July,August,September,October,November,December)[$mon];
  28.     $time = sprintf '%2.2d:%2.2d:%2.2d',$hour,$min,$sec;
  29.     $year += 1900;
  30.     $datetime = $thisday.', '.$thismon.' '.$mday.', '.$year.' '.$time;
  31.     $Response->write($datetime);
  32. %><BR>
  33.     </font>
  34.  
  35. <HR>
  36.     <%$N = 17;%>
  37.     <H1>Fibonacci numbers through <%= $N %></H1><BR>
  38.     Computations done via function calls<BR>
  39.  
  40.  
  41.  
  42.     <TABLE BORDER>
  43.     <%for ($i = 0; $i<$N; $i++){%>
  44.         <TR> 
  45.         <TD ALIGN=RIGHT><FONT SIZE=1> <%=$i%> </font></TD>
  46.         <TD ALIGN=RIGHT><FONT SIZE=2> <%$Response->write(&Fibonacci($i));%> </font></TD>
  47.         </TR>
  48.     <%}%>
  49.     </TABLE>
  50.  
  51.  
  52. <%sub Fibonacci
  53. {
  54.     local $i=$_[0];
  55.     local $fibA = 1;
  56.     local $fibB = 1;
  57.     if ($i == 0) 
  58.     {
  59.         return $fibA;
  60.     }
  61.     elsif ($i == 1)
  62.     {
  63.         return $fibB;
  64.     }
  65.     elsif ($i > 1) 
  66.     {
  67.         for ($j = 2; $j<=$i; $j++) 
  68.         {
  69.             $fib = $fibA + $fibB ;
  70.             $fibA = $fibB ;
  71.             $fibB = $fib;
  72.         }
  73.         return $fib;
  74.     }
  75. }  %>
  76. <!-- +++++++++++++++++++++++++++++++++++++
  77. here is the standard showsource link - 
  78.     Note that PerlScript must be the default language --> <hr>
  79. <%
  80.     $url = $Request->ServerVariables('PATH_INFO')->item;
  81.     $_ = $Request->ServerVariables('PATH_TRANSLATED')->item;
  82.     s/[\/\\](\w*\.asp\Z)//m;
  83.     $params = 'filename='."$1".'&URL='."$url";
  84.     $params =~ s#([^a-zA-Z0-9&_.:%/-\\]{1})#uc '%' . unpack('H2', $1)#eg;
  85. %>
  86. <A HREF="index.htm"> Return </A>
  87. <A HREF="showsource.asp?<%=$params%>">
  88. <h4><i>view the source</i></h4></A>  
  89.  
  90. </BODY>
  91. </HTML>
  92.  
  93.  
  94.