A program written by perl to randomly compile stories (rand Random Functions)

Source: Internet
Author: User

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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.