项目作者: luoye789

项目描述 :
Perl语言的相关学习资料
高级语言:
项目地址: git://github.com/luoye789/Perl.git
创建时间: 2016-11-17T00:25:35Z
项目社区:https://github.com/luoye789/Perl

开源协议:

下载


Perl

程序员编写的程序叫做源代码,简称为源/代码。模块就是Perl代码的集合。
常用模块:
1)随机选取数组的一个元素:

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. #声明变量
  5. my $count;
  6. my $input;
  7. my $sentence;
  8. my $story;
  9. my @nouns = ('Dad', 'TV', 'Mom', 'Rebecca', Joe and Moe',);
  10. my @verbs = ('ran to', 'giggled with', 'jumped with', dissolved', 'sang stupid songs with',);
  11. my @preposition = ('at the store', over the rainbow', 'just for the fun of it', 'in a dream', in New York City',);
  12. #随机选取数组的一个元素
  13. srand( time | $$ ); #time:进程ID; |:位或; $$:设置随机化种子(指定种子,固定的种子每次得到的结果一样)
  14. do {
  15. $story = ''; #清空一个字符串
  16. for ( $count = 0 ;$count < 6 ; $count++ ) {
  17. $sentence =
  18. $nouns[ int( rand( scalar @nouns ) ) ] . " " #函数scalar返回数组元素的个数 $verbs[ int( rand(7))]
  19. .$verbs[ int( rand( scalar @verbs ) ) ] . " " #rand(7)返回一个大于0,小于7的(伪)随机数,这是一个浮点数。
  20. .$nouns[ int( rand( scalar @nouns ) ) ] . " " #$verbs[int(3.47429)],[int(3.47429)]仅返回它的整数部分。
  21. .$preposition[ int( rand( scalar @preposition ) ) ] . '. '; #$verbs(3)则返回数组nouns的第四个元素。
  22. $story .= $sentence; $story .= =$story.$sentence
  23. }
  24. print "\n", $story, "\n" ;
  25. print "\nTepy \"quit\" to quit,or press Enter to continue: ";
  26. $input = <STDIN>;
  27. }until ( $input =~ /^\s*q/i );
  28. exit;
  29. 2)在字符串中选取一个随机位置
  30. 3)生成随机DNA(长度不一,每个位置上的碱基种类可能不同