Copy codeThe Code is as follows :#! /Bin/perl
Use strict;
Use warnings;
# Defining variables
My $ count;
My $ input;
My $ number;
My $ sentence;
My $ story;
# Define four arrays
# Defines the character array
My @ nouns =
(
'Dad ',
'TV ',
'Ms ',
'Groucho ',
'Rebecca ',
'Harpo ',
'Robin Hood ',
'Joe and moe ',
);
# Define the action Array
My @ verbs =
(
'Ran ',
'Giggled ',
'Put hot sauce into the orange juice ',
'Ploded ',
'Dissolved ',
'Dissolved ',
'Sang stupid songs ',
'Jumped ',
);
# Defines the location Array
My @ prepositions =
(
'At the store ',
'Over the rainbow ',
'At the beach ',
'Before dinner ',
'In New York city ',
'In a dream ',
'Round the world ',
);
Do
{
# Clear the content of $ story before each running
$ Story = '';
# The following is a story generated by a random combination.
For ($ count = 0; $ count <6; $ count ++)
{
# Divide the structure. scalar @ nouns is used to obtain the number of elements in the @ nouns array. Then, a few elements are randomly generated using the total number of rand. Finally, int Is Used to round the obtained number.
$ Sentence = $ nouns [int (rand (scalar @ nouns)]
.""
. $ Verbs [int (rand (scalar @ verbs)]
.""
. $ Nouns [int (rand (scalar @ nouns)]
.""
. $ Prepositions [int (rand (scalar @ prepositions)]
.'.';
$ Story. = $ sentence;
}
Print "\ n", $ story, "\ n ";
Print "\ nType \" quit \ "to quit, or press Enter to continue :";
$ Input = <STDIN>;
}
# The regular expression is used to match the string with the first character q. If yes, exit./^ indicates the starting position of the match and/I indicates case insensitive.
Until ($ input = ~ /^ \ S * q/I );
Exit;