#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
#say "Hello, World...\n";
for (my $i=1;$i<10 ;${i}++) {
#print "count $i!\n";
}
use File::Basename;
#use File::Basename (); #不引入函数
#use File::Basename qw / /;#不引入函数
#use File::Basename qw /basename/;#只引入basename函数
#use File::Basename;#引入所有函数
my $name = "/usr/bin/perl";
#my $basename = basename $name;
my $dir_name = File::Basename::dirname $name;
say $dir_name;
use File::Spec;
my $myoldname = "高级perl编程.pdf";
my $dirname = File::Basename::dirname $myoldname;
my $basename = File::Basename::basename $myoldname;
my $newname = File::Spec->catfile($dirname,$basename);
say $newname;
#use Path::Class;
#my $dir = dir(qw( Users fred lib ));
#say $dir;
#my $subdir = $dir -> subdir("perls");
#say $subdir;
#my $parent = $dir -> parent;
#say $parent;
#my $windir = $dir -> as_foregin("win32");
#say $windir;
my $filename = "perl_01";
my $filename2 = "perl_02";
my $filesize = (-s $filename) / 1000;
say $filesize;
warn "the file <$filename> already exist.\n"
if -e $filename;#文件是否存在
warn "the file <$filename> have 1 day not change.\n"
if -M $filename2 > 1;#最后一次被修改后至今的天数
warn "thie file <$filename2> size have > 11.\n"
if -s _ > 11; #文件大小,字节表示; -表示虚拟文件句柄,表示用上次查询过的文件来做当前测试
warn "the file <$filename> have 1 day not visit.\n"
if -A $filename > 1; #最后一次被访问后至今的天数
warn "the file <$filename> can read can write.\n"
if -w -r $filename;
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime) = stat($filename);
say $size;
say $atime;
my $date = localtime $atime;
say $date;
my($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime $atime;
say $year + 1900;#年
say $mon;#0-11 月份
say $wday;#0-6 星期
say $yday;#今天是今年的第几天
my $now = gmtime;
say $now;
chdir '/etc' or warn"cannot chdir to /etc:$!";#改变当前文件目录
chdir;
my @all_files = glob '*'; #文件名通配
say "@all_files";
my @pl_files = glob '*.pl';
say "@pl_files";
use File::Spec::Functions;
my $dir = 'D:\\lucene\\fileDir';
opendir my $files,$dir or warn "cannot open dir $dir $!.\n";
#foreach my $f(readdir $files){
# say "this is $f.";
#}
while(my $name = readdir $files){
next if $name =~ /^\./;
say $name."*****";
$name = catfile($dir,$name);#完整路径
say $name."+++++";
say "the dir $files have file $name.";
}
#unlink glob '*.pl';#删除文件
#unlink qw(file file1 file2);
#重命名文件
rename 'D:\\test\\test\\file\\aaaa.txt' => 'D:\\test\\test\\file\\a1.txt';
my $old_file = 'D:\\test\\test\\file\\a1.new';
my $new_file = $old_file;
$new_file =~ s/\.new$/.old/;#将a1.new 重命名为a1.old
if (-e $new_file) {
say "the file $new_file have exist!";
}elsif(rename $old_file => $new_file){
say "the file $old_file name have change $new_file!";
}else{
warn "the file $old_file rename $new_file fail. $!.";
}
my $tmp_dir = "D:\\test\\test\\file\\aaa_$$";
mkdir $tmp_dir ,0755; #创建目录
my $permissions = "0755";
mkdir $tmp_dir,oct($permissions);#转换成8进制
unlink glob "$tmp_dir/* $tmp_dir/.*";#删除目录中的文件
rmdir $tmp_dir; #删除空目录
$array[0]="hello";
$array[1]="world";
$array[2]="i";
$array[3]="am";
$array[4]="is";
$array[5]="gigg";
print $array[0]."\n";
$array[0]="hello,";
print $array[0]."\n";
$array["a"]="hello_aa"; #array index of "a" will be rest 0
$array[99]="beckham";
print $array[98]."\n";
print $#array."\n"; #array last one index
print $array[$#array]."\n"; #array end element
print $array[-1]."\n"; #array last one index
print $array[-2]."\n"; #array last two index
print $array[-200]."\n"; #array overstep
print "-------list-----------------\n";
@list1 = (1..10);
@list2 = (1.2..7.9);
@list3 = (5..1);
@list4 = ($m..$n);
@list5 = (1..$#array);
@list6 = (1,2,3..10,11,12);
@list7 = ("hello",4.7);
@list8 = (1,2,3,4,@list1);
@list9 = @list2;
($list[0],$list[1],$list[2],$list[3]) = ("giggs","beckham","kean","scholes");
($list[0],$list[1],$list[2],$list[3]) = qw( giggs bekcham kean scholes);
print $list[0]."\n";
#handler array to tail
$tmp = pop(@list1);
print $tmp."\n";
push(@list1,"tail_11");
print @list1;
print "\n";
#handler array to head
@arrays = qw < one two three four five six >;
$del_ele = shift(@arrays);
print $del_ele ."\n";
unshift(@arrays,"head_11");
print "-------splice------------\n";
@arrays = qw < one two three four five six >;
#splice(@arrays,1);
$del_eles = splice(@arrays,1,2);
print $del_eles."\n";
splice(@arrays,1,0,qw("hello"));
print "\@arrays elements is : (@arrays).\n";
print "\n";
@arrays = qw (one two three four five six);
print "this \@arrays[2] is $arrays[2].\n";
$arr = "ten";
print "this is @arrays[3].\n";
print "this is ${arr}[3]\n";
print "this is $arr"."[3]\n";
print "this is $arr\[3]\n";
print "---foreach-------"."\n";
foreach $item(qw< java c++ c c# python ruby perl >){
print "this is : $item.\n";
}
@rocks = qw / c# f# php /;
foreach $item(@rocks){
#item is @rocks elements
#$item = "\t$item";
$item = "\titem";
$item .="\n";
}
print "this \@rocks element is :\n",@rocks;
$items = qw / apple sanxing xiaomi /;
$item = "songxia";
foreach $item($items){
}
print "the \$item still is $item.\n";
#default variable is "$_"
foreach(1..10){
print "this is $_ .\n";
}
@array = (1..5);
@rev = reverse(@array);
print @rev;
print "\n";
@array = qw( one two three apple);
@sort = sort(@array);
foreach (@sort){
print "sort.this is:$_ .\n";
}
print "\n";
@number = sort(97..102);
print @number;
print "\n";
#use 5.012;
#my @rocks = qw( one two three );
#while(my($index,$value)=each @rocks){
# say "$index:$value";
#}
@rocks = qw ( one two three four five );
foreach $index(0..$#rocks){
print "$index:$rocks[$index]\n";
}
print "---------context----------------\n";
@array = undef; #error clear array
print @array."\n";
@array = (); #clear array
print @array."\n";
@array = qw( one two three four five six );
print "this is have ", @array ," elements!\n";
print "this is have ",scalar @array, " elements!\n";
@array = reverse qw( a1 b2 c3 d4 e5 );
print @array,"\n";
$array = reverse qw (a1 b2 c3 d4 e5);
print $array,"\n";
print "--------------example------------------\n";
#--first example--
#@list = <STDIN>;
#chomp(@list);
#@rev = reverse @list;
#foreach(@rev){
# print "current element is :$_.\n";
#}
#--second example----
#@list = qw(beckham giggs kean scholes);
#@recv = <STDIN>;
#chomp(@recv);
#foreach $index(@recv){
# print "the $index element is @list[$index-1]:\n";
#}
#---three example--------------
@recv = <STDIN>;
chomp(@recv);
print "the result is :\n";
foreach(sort @recv){
#print "the element is $_\n";
print "$_\t";
}
print "\n";
foreach(sort @recv){
print "$_\n";
}
分享到:
相关推荐
Perl是一种强大的脚本编程语言,...以上就是Perl学习笔记中涵盖的一些基础概念和操作。继续深入学习,你将能够编写更复杂的Perl脚本,解决各种实际问题。记得实践是学习编程的关键,多做练习,逐步提升你的Perl技能。
以下是对Perl学习笔记中提到的关键知识点的详细说明: 1. **标量**: 标量是Perl中最基本的变量类型,用于存储单个值,如字符串或数字。变量名前缀是美元符号“$”。例如,`$first_name = "Melanie"`定义了一个名...
Perl学习笔记中的所有脚本文件,https://blog.csdn.net/zgezi/category_10259467.html
### Perl学习笔记参考 #### Perl简介 Perl是一种高级编程语言,全称为Practical Extraction and Report Language,由Larry Wall创建,并持续由他进行更新与维护。Perl最初被设计用于Unix环境下的编程任务,随着...
本书是perl的经典入门书籍,介绍了perl中最基本的概念和语法,是perl入门的好书,我向所有想了解或学习perl语言的朋友推荐本书。书中穿插有perl语法形成的历史和原因,使你能充分感受到perl语言的文化,这也是perl...
Perl确实是一种非常吸引人的程序语言,而之所以这么引人入胜的原因不单单在于他的功能,也在于他写作的方式,或说成为一种程序写作的艺术。即使你只是每天埋首于程序写作的程序设计师,也不再让生活过份单调,至少你...
### Perl 语言学习笔记知识点概览 #### 第一章:Perl 语言简介及基础语法 - **Perl 的定义**:Perl 是 Practical Extraction and Report Language 的缩写,是一种强大的脚本语言,广泛应用于文本处理、系统管理...
### Perl语言学习笔记 #### Perl语言概述 - **高级语言与低级语言**: 在这篇笔记中,作者首先区分了高级语言和低级语言。高级语言指的是脚本语言,这类语言通常不直接操作底层硬件,例如Shell和Awk。低级语言则...
### Perl学习笔记:快速入门与面向对象编程 #### 基础概念介绍 Perl是一种功能强大的脚本语言,被广泛应用于系统管理、网络编程、文本处理等领域。它具有丰富的内置函数和灵活的数据类型,能够方便地处理各种复杂...
Perl是一种强大的脚本编程语言,尤其在文本处理和系统管理任务中广泛应用。...深入学习Perl,可以提升文本处理、系统管理以及自动化任务的效率。通过不断实践和探索,你可以掌握这个强大工具的所有潜力。
### Perl学习笔记关键知识点 #### 1. Perl简介 - **定义**:Perl是一种脚本语言,被设计用于处理文本文件、提取信息并生成报告。它由Larry Wall在1987年创建,目的是为了弥补当时其他语言如C、sed、awk等在处理文本...
这份"perl的学习笔记1"很可能是作者在深入学习Perl过程中积累的宝贵资料,包括他自己编写的小程序和学习心得。 首先,Perl语言的核心特性是其灵活性和适应性。它的语法混合了C、sed、awk等语言的特点,使得它既适合...
### Perl学习笔记 #### 第1章:Perl简介与基本语法 - **Hello, World!**:Perl中的第一个程序通常是从“Hello, World!”开始的。例如: ```perl #!/usr/bin/perl print "Hello, world!\n"; ``` 或者简化为: ...
Perl语言是一种功能强大的脚本编程语言,尤其适合文本处理和系统管理任务。本文将深入探讨Perl的命令行应用,帮助初学者快速入门。 首先,Perl有很多命令行参数,这些参数可以增强Perl程序的功能和安全性。其中,`-...
这个文档中记录和总结了我学习perl脚本语言的一些经验和初学者需要注意的事情