欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

perl寫的一個(gè)隨機(jī)編故事的程序(rand隨機(jī)函數(shù))

 更新時(shí)間:2013年03月20日 23:01:21   作者:  
用perl寫的一個(gè)隨機(jī)編故事的程序,用到了rand隨機(jī)函數(shù),注釋也很詳細(xì),需要的朋友可以參考下
復(fù)制代碼 代碼如下:

#!/bin/perl
use strict; 
use warnings; 

#定義變量 
my $count; 
my $input; 
my $number; 
my $sentence; 
my $story; 

#定義四個(gè)數(shù)組 
#定義了人物數(shù)組 
my @nouns= 

   'Dad', 
   'TV', 
   'Mom', 
   'Groucho', 
   'Rebecca', 
   'Harpo', 
   'Robin Hood', 
   'Joe and Moe', 
); 

#定義了動(dòng)作數(shù)組 
my @verbs= 

   'ran to', 
   'giggled with', 
   'put hot sauce into the orange juice of', 
   'exploded', 
   'dissolved', 
   'dissolved', 
   'sang stupid songs with', 
   'jumped with', 
 ); 

 #定義了地點(diǎn)數(shù)組 
 my @prepositions= 
 ( 
     'at the store', 
     'over the rainbow', 
     'at the beach', 
     'before dinner', 
     'in New York City', 
     'in a dream', 
     'around the world', 
 ); 

 do  
 { 
    #每次運(yùn)行以前,清空$story的內(nèi)容 
    $story=''; 
    #以下是隨機(jī)組合生成故事 
    for ($count =0;$count<6;$count++) 
    { 
       #我們劃分一下結(jié)構(gòu),scalar @nouns 是獲取@nouns數(shù)組元素的個(gè)數(shù),然后用rand總這幾個(gè)數(shù)中隨機(jī)生成幾個(gè),最后int是將得到的數(shù)取整 
       $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>; 

#這里是利用正則表達(dá)式來匹配首字符是q的字符串,如果有,那么就退出,/^是匹配起始位置,/i是不區(qū)分大小寫 
until ($input=~/^\s*q/i); 
exit;

相關(guān)文章

最新評(píng)論