home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Javascript / InteractiveWebDesignJavascript / Scripting / cgi1 / perl / cgi-bin / zippy.pl < prev    next >
Encoding:
Perl Script  |  2001-07-18  |  2.2 KB  |  87 lines

  1. #!C:/perl/bin/perl
  2.  
  3. # zippy.pl
  4. ######################################
  5. # Talk to Zippy
  6. #
  7. # A simple database of Zippy quotes
  8. # is displayed one line at a time
  9. # in response to user input
  10. #
  11. # Created: 1/31/2001
  12. # Author: Michael L. Curry 
  13. # http://www.web-data.org
  14. # email: mlcurry@web-data.org
  15. ######################################
  16. # Copyright 2001, This script may be 
  17. # distributed and modified as needed. 
  18. # Please credit the author.
  19. ######################################
  20. # C O N F I G U R A T I O N
  21. # Make sure that these files are in the
  22. # same directory as this script
  23. require("cgi-lib.pl");
  24. $zip_pic = "../zippy.gif";
  25. $zip_txt = "zippy.txt";
  26. $applet  = "zippy.pl";
  27.  
  28. # add the path to this CGI, without the file name!
  29. $path = "http://localhost/htbin/";
  30.  
  31. # that's it, your done!
  32. # Enjoy!
  33. ########################
  34. print "Content-type: text/html\n\n";
  35. &ReadParse(*form);
  36. $|=1;     # turn on error messages
  37. $cgi = $path . $applet;
  38. $you = $form{'T1'};
  39.  
  40. print <<HEADER;
  41. <html><head><title>Talk to Zippy</title>
  42. <script>
  43. function check()
  44. {
  45.     if (document.forms[0].T1.value == '') 
  46.     {
  47.         alert("Yow! Say something!");
  48.         return false;
  49.         }
  50.     else return true;
  51. }
  52. </script></head><body>
  53.  
  54. <p align="center"><img border="0" src=$zip_pic width="128" height="131"></p>
  55. <h2 align="center"><font face="Verdana">Hi, I'm Zippy, Talk to me!</font></h2>
  56. <form method="POST" action=$cgi onsubmit="return check()">
  57.  
  58.   <p><font face="Verdana"><input type="text" name="T1" size="42"><input type="submit" value="Yow!" name="B1"><input type="reset" value="Reset" name="B2"></font></p>
  59. </form>
  60. <p align="center"> </p>
  61. HEADER
  62. print "<p align='left'><font face='Verdana'><b>You Said:  $you</b></font></p>";
  63. print "<p align='left'><font face='Verdana'><b>Zippy Says: ";
  64.  
  65. open (DAT, "< $zip_txt") || die "Can't open $zip_txt:$!<br>";
  66. $knt = 0;
  67. while(<DAT>)
  68. {
  69.     $line = $_;
  70.     chop($line);
  71.     push (@zippy,$line);
  72.     $knt++;
  73. }
  74. srand;
  75. print "$zippy[rand $knt]";
  76. close(DAT);
  77. print <<FOOTER;
  78. </b></font></p>
  79. <hr>
  80. <p align="center"><font face="Verdana" size="1">Copyright ⌐2001 by <a href="mailto:mlcurry\@web-data.org">Michael
  81. Curry</a> Freely Use and Distribute, with this statement intact</font></p>
  82. </body>
  83. </html>
  84. FOOTER
  85.  
  86.  
  87.