Perl 沙漠之舟
bruce_wang_janet
人生有三宝:终身运动,终身学习,终身反醒.吸收新知,提高效率,懂得相处,成就自己,也成就他人,创造最高价值.
展开
-
mysql导出脚本自动生成word 数据字段perl工具
#!perl -wuse strict;use utf8;use open ':encoding(gbk)', ':std';use open ':encoding(utf8)';use Win32::OLE;use Win32::OLE::Const 'Microsoft.Word'; # wd constantsmy $word = Win32::OLE->原创 2017-10-27 19:44:39 · 750 阅读 · 0 评论 -
perl map 和grep使用
1.代码为:my @Array = (1,2,3,4);my @NewGrep = grep {$_*=2 if($_%2==1);} @Array;print "@Array \n";print "@NewGrep \n";my @NewMap = map {$_*=2 if($_%4==0);$_;} @Array;print "@Array \n";print "原创 2012-09-16 22:40:28 · 879 阅读 · 0 评论 -
看见一道排序题,练练手。
(编程题)100万个数据,数据值在0~65535之间,请用尽可能少的内存和最快的速度从小到大排序(10分) #!perl -wuse strict;my @ArrayData = (1,2,2,5,6,3,55,555,33,22,33,78,545,23,2,2,234,234,234,7,90,23,234,34,2,775,65);&Sort(@ArrayData);原创 2012-09-16 22:10:52 · 1267 阅读 · 0 评论 -
perl监控linux系统资源的脚步
#!/usr/bin/perl -wuse strict;my @MoniterDevideName=("cciss/c0d0p1","cciss/c0d0p3","sda");my @MoniterMountDir=("/");my $MoniterPeriod = 3;my $LogFileDir='./';my $HostName = (map {chomp;原创 2012-08-31 20:48:33 · 1059 阅读 · 0 评论 -
perl 匹配多个返回数组
perl 匹配多个返回数组my @Strings = ($NewString=~/(9\d{4})/g); my $NewString = "12312391293429342342139076856123";my @Strings = ($NewString=~/(9\d{4})/g);my @Result = sort @Strings;print "@Result原创 2012-08-28 20:58:01 · 2693 阅读 · 0 评论 -
perl 读写xml举例
1. xml脚本内容如下: 2 perl脚本如下:#!perl -wuse XML::Simple;use Data::Dumper;$xml = XMLin('NSN_ANALYSIS.xml', ForceArray => 1);print Dumper($xml);print "\n\n";my $i原创 2012-07-26 21:07:38 · 1949 阅读 · 0 评论 -
localtime函数可以实现获取时间信息
localtime函数,根据它所在的上下文,可以用两种完全不同的方法来运行。在标量上下文中,localtime函数返回一个格式化很好的当前时间字符串。例如,print scalar (localtime)这个代码,它输出的结果将类似于Thu Sep 16 23:00:06 1999。在列表上下文中,localtime将返回能够描述当前时间的一个元素列表:($sec,$min,$hour,$md原创 2012-07-22 22:03:10 · 2088 阅读 · 0 评论 -
perl 处理excel 实例
1. 实例说明 excel 模板先编写宏:NSN_HSPDA 关闭全部的excel文件,否则会出现无法完全关闭的问题 写excel文件,运行宏。 图表最好用公式先生成。 2. 代码 use Win32::OLE qw(in with);use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn =原创 2012-08-05 22:46:11 · 952 阅读 · 0 评论 -
perl 批量导入文件到sqlite3
1. 下载文件sqlite-shell-win32-x86-3071300.zip ,sqlite3的windows版本命令行程序2. 编写脚步 2.1 perl #!perl -wuse strict;my $CMD;my $DBName = "abcd.db";my $dbexcutesqlfile = "excute.sql";my $DBHandel;open原创 2012-07-14 14:05:54 · 1191 阅读 · 0 评论 -
perl 随机值,取整数方法
perl -e "print int(rand(40))"原创 2012-02-14 22:47:52 · 3648 阅读 · 0 评论 -
perl 模块化编程实例
1. 在当前目录创建 文件 Bruce目录,下面有Util.pm文件,内容如下:package Bruce::Util;use strict;use Exporter;use File::Path;our @ISA =qw(Exporter);our @EXPORT = qw(GetTimeStampStr CreateDirIfNeed LogMsg);our @EXPORT_原创 2012-01-26 14:41:24 · 1714 阅读 · 0 评论 -
perl 获取当前脚本的目录
1. 获取方法use File::Basename;print dirname(__FILE__);2. 设置当前目录为lib:use Cwd qw/abs_path/;use File::Basename;use lib abs_path(dirname(__FILE__)) . '/lib';原创 2012-01-26 10:57:23 · 5071 阅读 · 0 评论 -
Config::Std 使用
1. windows安装ppm install Config::Std2. 查看文件变化html增加了Std.html,site目录也增加了Class::Std.pm 和Config::Std.pm 是否将此文件直接复制过来就可以了??实验证实了,可以移动文件到其他机器上,去掉2个文件的use version; $VERSION = qv('0.0.9'); 就可以了直原创 2011-10-30 08:14:44 · 903 阅读 · 0 评论 -
$. 文件序列号
$. 是文件接口1. 准备文件welcome.txtD:\>type welcome.txtaasfdafafassfd adf2. 运行如下:D:\>perl -ne "print $.,':',$_" welcome.txt1:aasfd2:afaf3:4:as5:sfd adfD:\>perl -ne "print $.,':'原创 2012-11-16 21:16:56 · 761 阅读 · 0 评论 -
perl ole接口 API演示介绍
1. perl ole 接口演示use Win32::OLE;use Win32::OLE qw(in with);use Win32::OLE::Variant;use Win32::OLE::Const 'Microsoft Excel';$Excel = Win32::OLE->GetActiveObject('Excel.Application') ||Win转载 2012-11-25 23:52:22 · 2461 阅读 · 0 评论 -
perl glob 过滤文件列表
@html_file=glob '/home/site/*.html';@three_letter_extensions=glob '*.???';@lcfirst=glob '[a-z]*';@files=glob 'file[0-9][0-9][0-9]';@files=glob '???*';转载 2012-12-07 23:06:32 · 1343 阅读 · 0 评论 -
perl 生成json树
#perl -wuse strict;use Encode; #use Encode 'from_to';use Data::Dumper;use JSON; my @OrgRows = (); my %id_data = (); my %id_chirdren = ();my $firstid = "0"; &readdata();原创 2017-08-06 23:26:51 · 995 阅读 · 0 评论 -
重命名文件名称 rename
1. perl脚步print @ARGV;print "\n\n";if (@ARGV){ @filenames = ; print @filenames; foreach $filename (@filenames) { $newname = $filename; $newname =~ s#avi#mov#; print "rename $filename原创 2017-02-11 09:23:30 · 624 阅读 · 0 评论 -
perl 题目
1. 数组和列表量的区别 在标量环境下,数组返回数组长度。而列表值返回最后一个值。 列表(),会将小括号的东西放到堆栈中,使用时一个个弹出。2. use strict 和 use warnings 的作用use strict帮你寻找因为错误拼写造成的错误,解决命名变量问题。use strict 迫使你把变量的范围缩到最小,使你不必担心同名变量在程序的其它部份发生不良作用。原创 2013-09-03 21:52:04 · 950 阅读 · 0 评论 -
根据查询列名生成SQL的几个Perl代码
1. 代码#!perl -wuse strict;my $OrigSQL = q(select 'INDEXNAME','num' union all select * from (select conv(INDEXNAME,16,10),sum(1) as num from a_cell_kpi_ where tTime'2014-02-27 11:30:原创 2014-03-04 10:10:53 · 857 阅读 · 0 评论 -
分析UE log的工具
1. 目录截图2. 执行目录截图 3. perl 脚本代码#!perl -wuse strict;use Data::Dumper;use File::Basename;my $BinPath = (map{s#\n##g;$_} `cd`)[0];$BinPath .= "\\";my $MysqlClient = "${Bi原创 2014-02-28 22:04:54 · 2879 阅读 · 0 评论 -
C D S UeLog 处理RNTI,ENBID,CELLID的方法
思路根据目前的导出log格式,进行补充 3个信息 #!perl -wuse strict;use Data::Dumper;use File::Basename;my $BinPath = (map{s#\n##g;$_} `cd`)[0];$BinPath .= "\\";my $OutPutDir = $BinPath."..\\result\\";原创 2014-02-28 14:37:26 · 1860 阅读 · 0 评论 -
导入MySQL脚本生成SQL语句
window执行脚本%~d0cd %~p0perl makesql.pl >loadtables.sqlpause perl 代码:#!perl -wuse strict;my $BinPath = (map{s#\n##g;$_} `cd`)[0];$BinPath .= "\\";my $SQLPrefix = "LOAD DATA INFI原创 2014-02-28 16:16:10 · 1140 阅读 · 0 评论 -
perl 异常总结
1. Pseudo-hashes are deprecatedThe "Pseudo-hashes are deprecated" error means you're trying to access an array as a hash, which means that either$data->{file} or $data->{file}{path} is an arrayr原创 2014-02-16 13:44:20 · 774 阅读 · 0 评论 -
perl hash 按value/按keys 排序(多种方法)
use strict;my%hash=('a'=>2,'b'=>3,'c'=>1);foreachmy$key(sort{$hash{$b}$hash{$a}}keys%hash){ print$key,"=>",$hash{$key},"\n";}perl中如何将按hash key值排序如果是按ASCII码排序,则代码如下:foreach my $key ( sor转载 2014-02-04 22:06:09 · 33207 阅读 · 0 评论 -
perl 的md5函数应用
下面方法输出相同#!perl -wuse strict;use Digest::MD5;use Digest::MD5 qw(md5_hex);print "Digest is ", md5_hex("01232131231fddfsd"), "\n";my $md5 = Digest::MD5->new;my $Line = "01232131231fddfsd";原创 2014-02-04 09:50:40 · 4543 阅读 · 0 评论 -
时区转化和perl函数
整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC,Universal Time Coordinated)。UTC与格林尼治平均时(GMT, Greenwich MeanTime)一样,都与英国伦敦的本地时相同。在本文中,UTC与GMT含义完全相同。北京时区是东八区,领先UTC八个小时,在电子邮件信头的Date原创 2014-01-26 00:45:24 · 1627 阅读 · 0 评论 -
perl文件操作API
useCwd;my$dir = getcwd;useCwd 'abs_path';my$abs_path = abs_path($file)原创 2012-12-19 21:25:17 · 879 阅读 · 0 评论 -
perl 执行oracle存储过程,sql的方法
1. 采用DBI 需要安装 DBD-ORALCE才行,安装步骤比较复杂2. 采用sqlplus 执行命令 将执行语句,放到一个sql脚本文件中,如 execsql.sql. 将sql语句写入文件 my $SqlCMD = "************"; ` echo $SqlCMD >"$sqlfile"`; `echo exit原创 2011-10-25 21:30:03 · 3629 阅读 · 0 评论 -
perl 特殊变量
$- 当前页可打印的行数,属于Perl格式系统的一部分$! 根据上下文内容返回错误号或者错误串$” 列表分隔符$# 打印数字时默认的数字输出格式$$ Perl解释器的进程ID$% 当前输出通道的当前页号$& 与上个格式匹配的字符串$( 当前进程的组ID转载 2011-10-16 09:19:59 · 452 阅读 · 0 评论 -
log4perl 学习
1. windows 安装方法如下2. 测试 use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($DEBUG); my $logger = get_logger("Twix::Ba原创 2011-08-21 09:50:04 · 627 阅读 · 0 评论 -
通过unshift增加use,required 包命令路径
unshift(@INC,$BASE_DIR."lib"); unshift(@INC,$BASE_DIR."plugins");原创 2011-06-03 22:19:00 · 422 阅读 · 0 评论 -
第一个perl cgi请求示例
first perl cgi原创 2011-06-03 00:01:00 · 2280 阅读 · 0 评论 -
perl ibm相关经典文档集合链接
<br />http://www.ibm.com/developerworks/cn/linux/theme/perl/index.html原创 2011-02-16 21:01:00 · 628 阅读 · 0 评论 -
perl 面向对象基础总结
面向对象基础原创 2011-03-07 22:41:00 · 845 阅读 · 0 评论 -
perl ASCII码转换函数
chr 函数讲解原创 2011-03-04 09:01:00 · 2099 阅读 · 0 评论 -
perl 5.10后的新特征 given-when介绍
perl 5.10后的新特征 given-when介绍转载 2011-02-14 11:18:00 · 5025 阅读 · 2 评论 -
perl 5.10新特性智能匹配操作符合~~介绍
~~ 操作符号的 使用。原创 2011-02-14 10:56:00 · 1895 阅读 · 0 评论 -
perl 特殊变量总结
perl 特殊变量总结转载 2011-02-10 20:57:00 · 452 阅读 · 0 评论 -
最快的排序方法,以空间耗费为代价!!
用排序数字值作为数组的索引,其值来表示此数排序后的位置原创 2011-02-09 15:22:00 · 1065 阅读 · 0 评论