预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

Spring,2009 Perl入门和提高Lesson3 周晓方 courses@xfzhou.homeftp.org 1 Spring,2009 Sample •@s里面是一个spice文本,请把电容的容量加倍, 电阻的阻值减半;不考虑续行。 •提示,电容卡的格式是"C名称Node1Node2容量" @s=('RIN1210MEG', 'EGAIN3012100K', 'RP1341K', 'CP1401.5915UF', 'ROUT5610'); s/^(C(\S+\s+){3})([0-9\.]+)/$1.($3*2)/eforeach@s; /^R/ands/([0-9\.]+)(\S*)$/($1\/2).$2/eforeach@s; printjoin"\n",@s; 别忘了除法运算符/要转义 RIN125MEG EGAIN3012100K RP1340.5K CP1403.183UF ROUT565 2 Spring,2009 join,map,split,reverse,sort,grep join("\n",@array);#returnstring map("$_\n",@array);#returnarray printjoin"\t",map$_*$_,1..10; printjoin"\t",mapintrand(20),1..10; split(/pattern/,"string");#returnarray @list=split(//,"ABCDEFGHI");#qw(ABCDEFGHI) @list=split(/:/,"12:34:56:78",3);#qw(123456:78) reverse(@array);#returnarray数组反序 scalarreverse(@array);#合并成字符串,字符反序 %new_hash=reverse%old_hash;#交换哈希表的key和val sort(@array);#returnarray sort{$acmp$b}@list;#用法很丰富,参考perlop sort{$a<=>$b}@list; sort{-($a<=>$b)}@list; grep(/pattern/,@array);#returnfilteredarray @foo=grep(!/^#/,@bar);#removelinesstartwith# 3 Spring,2009 Hash表用于计数—单词统计 !/usr/bin/perl-w usestrict; =====Wordcount: my@lines=<DATA>;#Readindata chomp@lines;#RemoveCRLFthe9 my$line=lcjoin"",@lines;test1 $line=~s/[^a-z]+//g;#remove,:.()'explicitly1 my@words=split//,$line;you2 my@chars=split//,$line;normal1 print"=====Listofallwords:\n";file2 printjoin"\t",@words;exactly1 my($word,$char,$count,%words,%chars);that1 $words{$_}++foreach@words;my1 $chars{$_}++foreach@chars; print"\n\n=====Wordcount:\n";…… print"$word\t$count\n"=====Charcount: while($word,$count)=each%words;w1 print"\n\n=====Charcount:\n";a27 print"$char\t$count\n"r26 while($char,$count)=each%chars;x4 1;d11 __END__y9 Thereisoneminordifference:ifvariablesu4 aredeclaredwithmyintheinitialization h16 sectionofthefor,thelexicalscopeofthose ………… 4 Spring,2009 回家作业 •统计当前Win32系统上的TCP链接类型和数目,提 示1:用netstat-n-a命令,如下小型服务器上的统计 my@lines=split"\n",`netstat-n-a`; CLOSING4 然后历遍每一行进行统计,最后TIME_WAIT202 的统计结果输出成如下的格式:CLOSE_WAIT1 LISTENING128 TIME_WAIT5FIN_