perl trick
一、die if以及文件的操作
#!/usr/bin/perl -w
use strict; die "USAGE:\n\tperl $0 <><><>\n\n" if @ARGV != 3;
#$0表示脚本名,@ARGV表示参数个数 open (INPUT1 ,"$ARGV[0]") or die "can not open $ARGV[0]!"; open (QUERY ,"$ARGV[1]") or die "can not open $ARGV[1] !"; open (OUT ,">$ARGV[2]") or die "can not open $ARGV[2]!";
#注意下标是从0开始,>表示以写入方式打开 my %h; while(<INPUT1>)
{
chomp;
my @line = split"\t";
$line[0] =~ s/\s//g;
$line[2] =~ s/\s//g;
my $k = $line[0]."\t".$line[2];
$h{$k}=$k;
} my $header =readline(QUERY);#读取一行
print OUT $header;#写入用print my %header_idx; chop($header);
my @headers = split("\t", $header);#对变量进行split #scalar()获取数组长度
for(my $i=0; $i < scalar(@headers); $i++){
$headers[$i]=~s/\s//g;
$header_idx{$headers[$i]}=$i;
}
二、遍历哈希
while ( my ($key,$value) = each %ENV )
{
print "$key:$value\n";
}
三、时间打印
my $datestring = localtime();
print "starting time: $datestring \n"; #Fri Oct 19 15:36:21 2018这样的英文结果也许并不理想 sub sub_format_datetime {
my($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = @_;
$wday = $yday = $isdst = 0;
sprintf("%4d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon+1, $day, $hour, $min, $sec);
} #sprintf()函数
'''
$result = sprintf("%08d",$number);让$number有8个前导零。 $rounded = sprintf("%.3f",$number); 让小数点后有3位数字 '''
my $start = sub_format_datetime( localtime() );
print $start;
print "\n";
#2018-10-19 15:36:21变成中文时间
perl trick的更多相关文章
- Perl 之 use(), require(), do(), %INC and @INC
来源: http://www.cnblogs.com/itech/archive/2013/03/12/2956185.html 转自:http://perl.apache.org/docs/gene ...
- perl代码调试
perl调试教程 一.DESCRIPTIONA (very) lightweight introduction in the use of the perl debugger, and a point ...
- 转:perl源码审计
转:http://www.cgisecurity.com/lib/sips.html Security Issues in Perl Scripts By Jordan Dimov (jdimov@c ...
- 对MYSQL注入相关内容及部分Trick的归类小结
前言 最近在给学校的社团成员进行web安全方面的培训,由于在mysql注入这一块知识点挺杂的,入门容易,精通较难,网上相对比较全的资料也比较少,大多都是一个比较散的知识点,所以我打算将我在学习过程中遇 ...
- 精通Perl(第2版)
精通Perl(第2版)(通往Perl大师之路必读经典书籍,体现了一种编程思维,能够帮你解决很多实际的问题) [美]brian d foy(布瑞恩·D·福瓦)著 王兴宇 刘宸宇 译 ISBN 978 ...
- EEG preprocessing - A Trick Before Doing ICA
EEGLab maillist My ICs don't have high power in low frequency is b/c I do a small trick here. before ...
- perl
introduction: http://www.yiibai.com/perl/perl_introduction.html functions: http://www.yiibai.com/per ...
- Trick蠕虫病毒来袭!幕后主使竟是一名高中生“黑客”!
黑客一直是美国电影中的重要元素,很多经典大片中都有黑客的身影,如战争游戏.黑客帝国等.电影中黑客总是神通广大.行侠仗义,<战争游戏>中的年轻黑客大卫•莱特曼利用黑客技术避免引爆核武器,&l ...
- perl学习之路3
Perl编程之路3 标签: perl 列表与数组 Perl里面代表复数的就是列表和数组 列表(list)指的是标量的有序集合, 而数组(array)则是存储列表的变量. 在Perl这两个属于尝尝混 ...
随机推荐
- js中session操作
// 保存数据到sessionStorage sessionStorage.setItem('key', 'value'); // 从sessionStorage获取数据 var data = s ...
- [UOJ86]mx的组合数——NTT+数位DP+原根与指标+卢卡斯定理
题目链接: [UOJ86]mx的组合数 题目大意:给出四个数$p,n,l,r$,对于$\forall 0\le a\le p-1$,求$l\le x\le r,C_{x}^{n}\%p=a$的$x$的 ...
- HBase 清空表数据
public int clearTableByTableName(String tableName) throws Exception { logger.debug("======InitH ...
- windows 基础命令小集
windows 基础命令小集 winver---------检查Windows版本wmimgmt.msc----打开windows管理体系结构(WMI)wupdmgr--------windows更新 ...
- 爬虫_中国天气网_文字天气预报(xpath)
import requests from lxml import etree headers = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/5 ...
- Coding and Paper Letter(五十八)
资源整理. 1 Coding: 1.支持TMS.WMTS标准瓦片下载,支持百度地图瓦片.高德地图瓦片.腾讯地图瓦片.天地图.ArcServer Rest瓦片.ArcServer本地缓存切片.geose ...
- CSS圆角进化论
CSS圆角发展过程 大致经历了3个阶段,包括: 背景图片实现圆角 CSS2.0+标签模拟圆角 CSS3.0圆角属性(border-radius属性)实现圆角 ☛背景图片实现圆角:==使用背景图片实现 ...
- springboot jar包运行中获取资源文件
1. 今天晚上写了一个程序,基于Spring boot的一个小网站,发现使用FileUtils.class.getResource(path)来获取jar包中的资源文件并不能成功,其路径很奇怪 fil ...
- nodejs的某些api~(一)node的流2
可写流writablewritable.write(chunk, [encoding], [callback])chunk {String | Buffer} 要写入的数据encoding {Stri ...
- P1024 一道naive的二分
好吧,这道题思路还是比较简单的.整个程序大体上很快就打出来了,然后修改了解为整数的情况. 但是交上去一直是50分,最后我很无耻的看了题解,然后抄了一个玄学if回来,瞬间AC,不知道为什么... 这句就 ...