perl 获取 日期 yyyy-mm-dd
#!/usr/local/bin/perl use strict; use warnings; my ($year,$mon,$day)=(localtime)[5,4,3]; $year+=1900; $mon+=1; $day-=1; my $today=sprintf("%04u-%02u-%02u",$year,$mon,$day); print("$todayn");[@more@]
去掉两个字人名中间的空格
while(<>){@name=split (" ",$_);open FH,">>name_file.txt";my $i=0;while ($i <=$#name){ $length=length($name[$i])/2; if ($length>1) { print FH "$name[$i] "; } elsif($length=1){ print FH "$name[$i]$name[$i+1] " ; $i+=1; } $i+=1;}print FH "n";}close FH;[@more@]
perldoc 常用命令(参数)
1.查找函数文档perldoc -f substr2.查找faqperldoc -q substr3.查找module路径perldoc -l IO::File4.查代码perldoc -m IO::File[@more@]
用perl按记录条件分割大文件
《intermediate perl》一书中第8章练习2是一个分割文件的练习Gilligan: 1 coconutSkipper: 3 coconutsGilligan: 1 bananaGinger: 2 papayasProfessor: 3 coconutsMaryAnn: 2 papayas.......要求按照:前的字符将原始文件分割成若干个*.info文件可以有2种方法解决1、#!/usr/local/bin/perl use strict;use warnings;use IO::File;my %output_handles;while (<>) {unless (/^(S+):/) {warn "ignoring the line with missing name: $_";next;}my $name = lc $1;my $handle = $output_handles{$name} ||=my $fh =IO::File->
perl ->
-> 有两种用法,都和解引用有关。第一种用法,就是解引用。根据 -> 后面跟的符号的不同,解不同类型的引用,->[] 表示解数组引用,->{} 表示解散列引用,->() 表示解子程序引用。例子:$arr_ref = @array;$arr_ref->[0] 访问数组 @array 的第一个元素。$hash_ref = %hash;$hash_ref->{foo} 访问 %hash 的 foo 分量$sub_ref = &test;$sub_ref->(1, 2, 3) 使用参数列表 (1,2,3) 来调用 &test 这个子程序。第二种用法,就是调用类或者对象的方法。格式:$obj->method();或者ClassName->method();例如: