#!/usr/local/bin/perl ############################################################################### # # # Phrase # # v1.0 # # (c) 2000 Anatoli Klassen # # # ############################################################################### use strict; use vars; ### Settings ################################################################## my $root_name; # root directory for all files, by default the directory # with the script, must finish with slash (for UNIX) # or backslash (for Windows) my $phrases_name = "../../../data/public/phrase/phrase.txt"; # file with phrases my $view_name = "phrase.html"; # file with template for view ### Main Part ################################################################# # Global variables declaration my $file_name; # name of file with the script my $script_name; # name of the script without directory my $phrase; # a phrase to output local *MSGFILE; # Form name of files and directories $file_name = __FILE__; $script_name = $file_name; $script_name =~ s|(.*/)||; $script_name =~ s|(.*\\)||; if (!defined($root_name)) { if ($file_name =~ m|\\|) { ($root_name) = ($file_name =~ m|(.*\\)|); } else { ($root_name) = ($file_name =~ m|(.*/)|); } } # Create HTML header print "Content-type: text/html\nPragma: no-cache\n\n"; # Read data from the file my $count = 0; if (open (MSGFILE, "<$root_name$phrases_name")) { while () { $count++; } close (MSGFILE); } my $number = int rand $count-1; $count = 0; if (open (MSGFILE, "<$root_name$phrases_name")) { while (my $line = ) { if ($count == $number) { $phrase = $line; last; } $count++; } close (MSGFILE); } # Form and output the page my $template_name = $root_name . $view_name; my $template = ""; if (open (TEMPLATEFILE, "<$template_name")) { while (my $line = ) { $template .= "$line"; } close (TEMPLATEFILE); } if (!$template) { $template = "Internal server error."; } $template =~ s|<#main>|$phrase|gi; $template =~ s/<#scriptname>/$script_name/gi; $template =~ s/<#filename>/$file_name/gi; print $template; __END__ ### EOF #######################################################################