#!/usr/bin/perl -w
%hash = ();
open(FILE, "story.txt") || die ; #opens file story.txt
while ( $story[$i++] = <FILE> ){ } #moves story.txt to @story
close (FILE); #closes Story.txt
foreach $list ( @story )
{
@temp = split(/ /, $list); #puts word by word in @temp
$i=0;
while ($i <= $#temp)
{
$word=$temp[$i];
if ( $word =~ /^\[/ && $word =~ /$\]/)
{
if (! exists $hash { $word } )
{
$auxiliary_word = $word;
$auxiliary_word =~ tr/\[/ /; #removes front bracket
$auxiliary_word =~ tr/\].,?/ /; #removes rear bracket & pu
+nctuation
$capitol = 0;
if ($word =~ /^\[[A-Z]/) #checks for capitol letter
{
$capitol = 1;
}
Replace($word,$capitol); #function call to enter own word
+s
}
}
$i++;
}
}
Print(); #print final madlib story
#*****************************************************************
sub Replace #user enters own words
{
print" Please enter a $auxiliary_word: ";
$new_word = <STDIN>;
if ($capitol == 1 )
{
$new_word =~ s/(^[a-z]+)/\u$1/; #makes first letter capitol
}
chomp ( $new_word );
$hash { $word } = $new_word; #adds capitol letter t
+o hash
}
#*********************************************************************
sub Print #function to print new story
{
foreach $list ( @story )
{
@temp = split(/ /, $list);
$i=0;
while ($i <= $#temp)
{
$word = $temp[$i];
if ($word =~ /^\[/ && $word =~ /$\]/)
#if ( $word =~ m/\B[[A-Za-z]]/g)
{
$temp[$i] = $hash { $word };
}
$i++;
}
$final = join(' ', @temp); #joins story together
print $final; #prints new story
}
}
Strangeness in Cars
I once owned a [noun] that was [adjective] only when ,
in a [Make-of-car]. Some [plural-noun] thought,
[adverb], that this was [another-adjective], but what did
they [verb]. Anyway, now I am [comparative],
and don't [verb] so much, even when in [make-of-car]
cars. Do you think that's [another-adjective], or
should I [strange-action-verb]?
|