Perl
文章平均质量分 86
xiaomifeng713
两只小蜜蜂啊飞到花丛中啊飞啊飞啊
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
each的用法及while 的使用方法
#!/user/bin/perlmy @rocks = qw / bedrock salate rubble granite / ; while (my( $index,$value)= each @rocks){ print "$index: $value \n"; } print "哈哈:\n"; #两种相同的写法foreach $index (0 .原创 2016-12-14 18:10:19 · 586 阅读 · 0 评论 -
调用windows set命令,查找 环境变量中带有java的环境变
my $now=`date`.`time`;print "the time is now $now.\n";my $who_text=`set`;my @who_lines=`set`;print "----------------------------------------------------\n";my $num=$#who_lines; my $i=0;for ($i原创 2017-01-04 16:55:54 · 359 阅读 · 0 评论 -
perl-指定目录下面修改某文件的名字及修改此文件中的内容
#!/usr/bin/perl -w use strict ; chomp(my $date=`date`);@ARGV=glob "aa.dat" or die "no files found";$^I=".bak";while ( { s/^aaa:*/aaa:change value/; s/^bbb:.*\n//; s/^ccc:.*/ccc:$date/; print ; }原创 2017-01-04 16:54:02 · 1715 阅读 · 0 评论 -
正则表达式 例子
#! /usr/bin/perl –wmy $what = "fred|test"; # 在此处。| 相当于或的意思while(<>){if(/^($what)/){ # 匹配行开头是 fred或test的数据,如果是,通过 ifprint "We saw $what in beginning of $_;";}}利用正则:my $line = 'how old are yo原创 2016-12-19 14:45:25 · 269 阅读 · 0 评论 -
正则表达式 常用的正则
/yes/i # 匹配 yes的 不区分大小写/s # 匹配 任何字符/x # 添加空格 /U #要求紧接着的都是大写/L #要求后面的全部是小写 -? #可选的负号\d+ #小数点前一个或多个十进制数字\.? #可选的小数点\d* #小数点后一些可选的十进制数字/x #模式结束 /\bfred/b\ # 匹配 fred 只能/\bhunt/ #将匹配 hun原创 2016-12-19 14:43:48 · 342 阅读 · 0 评论 -
写一个名为 &total 的子程序,返回一列数字的和
sub total { my $sum=0; foreach (@_) { $sum=$sum+$_; } $sum; } my @fred = 1 .. 1000 ;$fred_total=&total(@fred);print $fred_total,"\n";原创 2016-12-19 14:42:05 · 695 阅读 · 0 评论 -
perl 生成SQL语句
如上图显示,在公司每当起一个新项目时,都需要分析一些常用字段,及字段类型、字段长度。那分析完后,要需要对数据库进行相应的建表操作了,当然现在有很多工具,比如:powerdesin、ERwin之类的建模工具能省任,那比如公司给提供了一个类似excel这类的数据,用手工来完成,这太费事了,所以才有这个想法。使用Perl脚本,对excel进行读取操作,然后根据相应的格式,生成对应的SQL语句。#原创 2016-12-21 15:09:44 · 2639 阅读 · 0 评论 -
查看本机中所有perl已经安装的模块
在学习perl中,经常会下载一些模块,有些模块本来已经存在,因为刚学习,并不知道这些模块的名称及作用,所以需要打印出来,又因为安装的模块太多,打印出来的东西太多,看的不是很连惯,所以要使用以下命令操作:windowns 如下操作: C:\Users\user>perldoc perllocal >d:\1.txt这把就把文件信息保存到D盘下的1.txt文件中。我们再原创 2016-12-09 11:01:49 · 3385 阅读 · 0 评论 -
显示一个目录内所有文件,及有条件的过滤某些文件
#!/usr/bin/perl opendir (DIR,'./test/test') or die "Cont't open directory,$!";while ($file=readdir DIR) { print "$file\n"; ## 打开一个目录,并列了目录内的所有文件 } closedir DIR;print "*************************原创 2016-12-05 18:29:11 · 559 阅读 · 0 评论 -
调用子程序来返回 某个字段在数组中的位置
my @names = qw / fred test dfdf dino abcde/;my $result=&max("dino",@names);sub max { my($what,@array)=@_; foreach(0..$#array) { if ($what eq $array[$_]) { return $_+1; } } -1; }原创 2016-12-14 18:14:29 · 482 阅读 · 0 评论 -
($m)与$m 变量 赋值时要注意的地方
#!/user/bin/perl@m=qw / bcddd b c d e f g /;($x)=@m; #### 这种操作得到 数组中 第一组 数 $y=@m; #### 这种操作奖得到数组中,有几个变量的个数print $x,"\n";print $y,"\n";print $x[0],"\n";print @m,"\n";print $m[1],"\n";#!/us原创 2016-12-14 18:13:27 · 875 阅读 · 0 评论 -
读取几行数据,反向显示
#!/user/bin/perlprint "enter some lines, then press ctrl+Z \n";@lines=<>;@reverse_line= reverse @lines;print @reverse_line;原创 2016-12-14 18:12:39 · 388 阅读 · 0 评论 -
splice的用法
#!/user/bin/perl@array=qw ( pebbles dino fred barney betty);@removed=splice @array ,1,2,qw (abc bcd def);print @removed,"\n";print @array ,"\n";原创 2016-12-14 18:11:55 · 524 阅读 · 0 评论 -
scalar 函数的使用
#!/user/bin/perl@rocks=qw( talc quartz jade obsidian);print "How many rocks do you have ?\n";print "i have ",@rocks," rocks!\n";print "i have ",scalar @rocks , " rocks!\n"; #print @rocks+1-1;#s原创 2016-12-14 18:11:21 · 10269 阅读 · 0 评论 -
打开一个txt文件,读取里面的内容并打印出来
#!E:\Dwimperl\binopen(FILEIP, "E:/Dwimperl/program/test/file3.txt"); ### 打开别的盘的文件while(){ chomp ; # 去除换行 s/00000//ig; print $_."\n"; }close (FILEIP)my $file = "file.tx原创 2017-01-04 16:57:06 · 5387 阅读 · 0 评论
分享