#!/usr/bin/perl ########################################################################## # widgets.pl Version 2.0 September 26, 1996 # # Displaying a random widget from a file of widgets. Can be used for # # random thoughts, tips, even HTML body tags, for random colors. # # Copyright 1996 by Urb LeJeune, lejeune@charm.net # # Last modified on September 26, 1996 # ########################################################################## # COPYRIGHT NOTICE # # Copyright 1996 Urban A. LeJeune. All Rights Reserved. # # This script, with or without modifications, may be freely copied, # # reproduced, distributed, or used in any fashion provided the file # # remains intact with copyright notice. # # # # Please let me know if you use hit script so I can keep you informed # # of changes, modifications or (horrors) bug fixes. # # America's Town Square e-mail to lejeune@charm.net # # 15 Hunter Drive # # Tuckerton, NJ 08087 Phone (609) 294-0320 # ########################################################################## # Data for the random widget generator should be in a plain text # # file with individual widgets being separated by "(1)" (without the # # quotes), unless the delimiter variable is changed below. # # The data file is assumed to have the same name as the calling # # HTML document. It is additionally assumed the widget file extension # # is "txt" unless the extension variable is changed below. It is also # # assumed the widget file will be in a subdirectory immediately under # # the directory containing this script. Change the path variable if the # # assumption is not true. To illustrate, if you call this script from # # a document called thoughts.html, the script will open # # /data/thoughts.txt and parse the file delimited by (1) # ########################################################################## print "Content-type: text/plain\n\n"; # Script variable, change if assumptions are wrong. $WidgetDelimiter = "\\(1\\)"; # Assumes widgets are separated by (1) $WidgetExtension = ".txt"; # Assumes widget file extension of txt $WidgetPath = "data/"; # Assumes path data under the script path $WidgetFile = $ENV{'DOCUMENT_URI'}; # Get name of calling HTML file $_ = $WidgetFile; # Set up for regular expression $WidgetFile =~ m!.*/(.*)\.!; # Put extensionless file name in $1 # Add "data/" to path and ".txt" to file name $WidgetFile = "$WidgetPath$1$WidgetExtension"; open(WIDGET, "$WidgetFile") || # Open the file die "Cannot open $WidgetFile\n"; # Bummer if you get here @widget = ; # Suck up file into array $bigdata = join("",@widget); # Transfer file to scalar variable @widget = split(/$WidgetDelimiter/,$bigdata); # Break widgets into array #@widget = split(/\(1\)/,$bigdata); # Break widgets into array $WidgetCount= @widget; # Number of widget elements srand(); # Seed random number generator $WidgetIndex = int(rand($WidgetCount)); # Get random number for array print "$widget[$WidgetIndex]"; # Display the random widget