随笔分类 -  perl

perl
摘要:Perl 使用Log4perl首先下载log4 module :http://search.cpan.org/CPAN/authors/id/M/MS/MSCHILLI/Log-Log4perl-1.43.tar.gz解压配置:这里只用到lib目录下的文件,可以将其他目录删除。如何使用这个模块:新增... 阅读全文
posted @ 2014-04-22 14:44 to be crazy 阅读(3413) 评论(1) 推荐(1) 编辑
摘要:今天写脚本遇到Can't use string ("bond2 Link encap:InfiniBand ") as a symbol ref while "strict refs" in use at test.pl line 的错误google了一下,发现stackoverflow有这样的... 阅读全文
posted @ 2014-04-16 15:37 to be crazy 阅读(4971) 评论(0) 推荐(1) 编辑
摘要:2013的最后一天,盘点一下过去,展望一下未来。 既然是打击式的成长,那就越挫越勇。 不知不觉,已经在这家公司待了一年半,从年初到年末,成长许多,进步许多,有过浮躁,有过懈怠,有过失望,更多的是不甘平庸的心。下面就从职场和情场说起: 工作上,接触perl/shell,从开始的维护脚本,压根就看不懂,不知所措的状态,到现在的游刃有余,弹指一挥间,漂亮的代码高效快捷的完成一个个test case。众所周知,perl代码可读性极差,但很简洁,举个栗子: 把数组赋给变量,变量拿到的是数组的长度,哈希赋值给变量拿到的却是一个类似分数的值,很方便的交换值($var1... 阅读全文
posted @ 2013-12-31 19:42 to be crazy 阅读(801) 评论(3) 推荐(0) 编辑
摘要:perl没有真正的二维数组,所谓的二维数组其实是把一维数组以引用的方式放到另外一个一维数组。二维数组定义 :my @array1=([1,2],[3,4],[45,9],[66,-5]); [1]$array1[1] 代表数组的地址例子:#!/usr/bin/perl -wuse strict;my @array1=([1,2],[3,4],[45,9],[66,-5]);print $array1[1][1] ;print $array1[1]->[1];print $array1[1];my @array2=qw/this is a array/;my @array3=(" 阅读全文
posted @ 2013-10-26 00:27 to be crazy 阅读(6422) 评论(0) 推荐(1) 编辑
摘要:perl 返回文件句柄的2种方式1.使用 \*#!/usr/bin/perluse strict;sub openfile(){ my $path=shift; open(FILE,"$path") or die "Can't open $path $!\n "; return \*FILE; }my $temp=&openfile("config");my @file=;print @file;2.使用变量#!/usr/bin/perluse strict;sub openfile(){ my $file; my $ 阅读全文
posted @ 2013-08-01 23:43 to be crazy 阅读(3928) 评论(0) 推荐(1) 编辑
摘要:最近在写一个perl函数,把test case 放到配置文件里,读出来然后使用system运行。我的本意是: 配置文件conf ping -c $count $ip #在主程序中定义$ip和$count 从配置文件中拿出这句ping -c $count $ip 将其在system中执行,其中事先定义好$count=10 $ip="192.168.1.1"; #!/usr/bin/perl -wuse strict;my $ip="192.168.1.1";my $count=10;open(CONF,"conf") or die &q 阅读全文
posted @ 2013-07-19 21:32 to be crazy 阅读(721) 评论(0) 推荐(0) 编辑
摘要:1.数组相等,数组成员相同,位置也相同一般的如果判断@array1等于 @array2a.数组长度相同 $#array1=$#array2, 比较数组长度,不能使用length函数,length只适用string类型数组参数传递,不能直接传递sub compare(){ my $flag=0; my ($first,$second)=@_; if (@$first==@$second) # the number of the array , don't use length() { for(my $i=0;... 阅读全文
posted @ 2013-06-28 23:16 to be crazy 阅读(7200) 评论(0) 推荐(0) 编辑
摘要:1.q 相当于 单引号' ' 转义字符无效 q可以使用()[] {} // ,,2.qq 相当于" " 转义字符有效 qq可以使用()[] {} // ,,3.qw 相当于 ('' ,'' ,' ')在每一个单词上添加 ' ' 转义字符无效 qw可以使用()[] {} // ,, qq 和qw 区别,qq赋给数组是整体赋给数组的一个元素,而qw则会每个单词算作一个数组元素4.qr 相当于创建正则 qr//5.qx 执行外部程序 相当于`` 1 #!/usr/bin/perl 2 use stri 阅读全文
posted @ 2013-06-28 22:28 to be crazy 阅读(14629) 评论(0) 推荐(0) 编辑
摘要:1. 普通变量引用 variable reference 引用就好比C语言的指针,引用变量存储被引用变量的地址。赋值时注意要在变量前加上 \;使用时要多加一个 $ 。 当然,引用也可以成为简单变量,可以使用引用的引用,使用时要记得多加一个$.引用也可以互相赋值 1 #!/usr/bin/perl -w2 my $variable="this is a reference test\n";3 my $refv=\$variable;4 my $refr=\$refv;5 print "this is \$refv:$refv\n";6 print &quo 阅读全文
posted @ 2013-06-24 16:48 to be crazy 阅读(788) 评论(0) 推荐(0) 编辑
摘要:1. tr 转换 转换不是替换(tr///==y///)tr/searchlist/replacementlist/用于查找某个一个字符串,并用replacementlist替换,可以使用正则表达式my $str="this Is A teST";$str=~tr/a-z/A-Z/; 把小写转换为大写 会输出THIS IS A TESTs/// optionsg 全局替换i 忽略大小写my $str3="this is a test\n";$str3=~s/t/haha/g; =====>hahahis is a hahaeshahaprint $ 阅读全文
posted @ 2013-06-17 23:57 to be crazy 阅读(420) 评论(0) 推荐(0) 编辑
摘要:1.使用system函数 运行成功,返回0,运行失败则返回非负整数system("cmd");2.使用qxmy $cmd1=qx/date/;3.使用`` 与qx等效4.使用open函数open(CMD,“ifconfig |”) or die $!my @result=;close(CMD);5.使用readpipe函数使用readpipe函数可以获取外部程序运行的结果,比如运行 ls 会列出当前目录的文件和文件夹,my $result=readpipe("ls ");#!/usr/bin/perluse strict;my $return=syste 阅读全文
posted @ 2013-06-17 21:23 to be crazy 阅读(1588) 评论(0) 推荐(0) 编辑
摘要:1. index 函数 index 主要用于字符串查找,返回从左->右查到子字符串的起始位置(起始位置0) ,可以带括号,也可以不带。当找不到会返回-1使用方法: index STR,SUBSTR,POSITION index STR,SUBSTR实例:#!/usr/bin/perluse strict;my $str1="Love me, love my dog\n";print "return the first child string location\n";print index $str1,"ove";print & 阅读全文
posted @ 2013-06-16 00:05 to be crazy 阅读(1378) 评论(0) 推荐(0) 编辑
摘要:1.参数传递 普通模式:参数中没有数组和哈希#!/usr/bin/perl -wuse strict;sub getparameter{ my $i; for( $i=0;$i<=$#_;$i++) { print "It's the "; print $i+1; print " parameter:$_[$i]\n"; }}无论参数有多少个,均能正常传递。调用函数&getparameter($first,$second .. $end)文艺模式:参... 阅读全文
posted @ 2013-06-11 16:35 to be crazy 阅读(28603) 评论(0) 推荐(1) 编辑
摘要:之前有比较笼统的写过关于自动化的一些思考(一)http://www.cnblogs.com/tobecrazy/archive/2012/12/18/2824248.html那时候刚做自动化不久,对很多问题的认识和感受不够深刻,就现在而言,我依然是自动化测试的一枚新兵蛋子,还有很多的知识需要了解。回顾一下当时只是弄清楚了一个问题 why,为什么要进行自动化测试,自动化主要还是用于regression,对于测试new feature和new bug,毫无意义,接下来是要弄清楚这个问题:how1.自动化测试分类 我的分类标准是工具,根据不同的工具进行分类。 基于GUI的功能测试工具QTP(现UFT 阅读全文
posted @ 2013-06-10 22:39 to be crazy 阅读(2906) 评论(0) 推荐(0) 编辑
摘要:1.什么是哈希 哈希是perl的一种数据类型,比较类似数组,用于存放数据,包括2部分关键字keys和值value。不同于数组,哈希访问元素的是按照名字访问标量的key=>value.hash 用% 来标示2.hash 操作 a.增加 my %hash; //定义 第一种写法:$hash{'author'}="Young"; #author 是关键字,Young 是value 与数组一样,hash作为整体时候是这样%hash 带标示符%,作为单个元素使用要使用$而不是%第二种写法:my %food=('fruit',"apple 阅读全文
posted @ 2013-06-09 13:34 to be crazy 阅读(36276) 评论(0) 推荐(0) 编辑
摘要:使用perl统计字数,使用正则表达式和hash首先去掉非显示字符(换行 空格)其次把大写转换为小写word.txt 原文A coal factory in Anhui province. The United States will pursue opportunities to increase coal exports to China, says Platts' Coal Trader International. Provided to China Daily US expected to increase exports to China and Europe as powe 阅读全文
posted @ 2013-05-24 17:34 to be crazy 阅读(2333) 评论(0) 推荐(0) 编辑
摘要:1. 正则表达式email:=~ /^([0-9a-zA-Z]{3,}|[0-9a-zA-Z]+(-|_)?[0-9a-zA-Z_-]+\.?[0-9a-zA-Z]+)\@[0-9a-zA-Z]+\.[0-9a-zA-Z]+(\.\w+)?/;ip =~/([0-9]{1,3}\.?){4}/;. Match any character except a wrap character.\w Match "word" character and [_0-9a-zA-Z]\WMatch non-word character [^_0-9a-zA-Z]\s Match white 阅读全文
posted @ 2013-01-05 00:04 to be crazy 阅读(1566) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示