perl学习
文章平均质量分 63
唐不甜-
小菜鸟在CSDN向dalao们学习
展开
-
perl语言入门级练习记录10章&11章&13章 控制结构和一些文件处理 排序 Hash哈希
10.10 练习[25]写一个程序,能重复要求用户猜测某个在1 到100 之间的数字,直到猜对为止。你的程序应当能随机的产生一个数字,使用公式int(1 + rand 100)◆。当用户猜测错误时,程序应该回应“Too high”或者“Too low”。如果用户输入quit或exit,或者回车时,程序应立即退出。如果用户猜测正确,程序也退出。#! /usr/bin/perl –wuse strict;my $num=int(1 + rand 100);print "Guess the r原创 2021-03-20 14:05:20 · 105 阅读 · 0 评论 -
perl语言入门级练习记录8&9章 正则表达式 匹配 替换
8.10 练习[8]使用模式测试程序。创造一个模式能匹配字符串match。使用字符串beforematchafter 进行测试。输出结果将其三部分放在正确位置了吗?#!/usr/bin/perl –wuse strict;$_="beforematchafter"; (/(.*)(match)(.*)/)and print "Matched:[$1<$2>$3]\n" or print "no match:|$_|\n"; 1;[7]使用模原创 2021-03-20 11:04:11 · 177 阅读 · 0 评论 -
perl语言入门级练习记录6&7章 哈希Hash 正则表达式
6.5 练习[7]写一个程序,提示用户输入given name(名),并给出其对应的family name(姓)。#!/usr/bin/perl –wuse strict;my %name = ( "fred" => "flintstone", "dino" => "und", "barney"=> "rubble", "betty"=> "rubble", "jingyi"=>"wang", "yq"=>"lee", "notsweet"=&原创 2021-03-19 17:18:52 · 196 阅读 · 1 评论 -
perl语言入门级练习记录4&5章
4.11 练习[12]写一个名为&total 的子程序,返回一列数字的和。提示:子程序不应当有任何的I/O 操作;它处理调用的参数,返回处理后的值给调用者。结合下面的程序来练习,它检测此子程序是否正常工作。第一组数组之和我25。my @fred = qw{ 1 3 5 7 9 };my $fred_total = &total(@fred);print “The total of @fred is $fred_total.\n”;print "Enter some number原创 2021-03-19 09:25:54 · 134 阅读 · 0 评论 -
perl语言入门级练习记录2&3章
题目来自《Perl语言入门》第四版 2.1.2练习[5]写一个程序,计算半径为12.5的圆的周长。圆周长等于2π(π约为3.1415926)乘以半径。答案为78.5。#!/usr/bin/perl –wuse strict;my $pi=3.141592654;my $r=12.5;my $c=2*$pi*$r;printf "The C is %.1f\n",$c;[4]修改上述程序,用户可以在程序运行时输入半径。如果,用户输入12.5,则应得到和上题一样的结果。#!/原创 2021-03-18 20:50:08 · 217 阅读 · 0 评论