相关文章推荐
小胡子的火锅  ·  Android ...·  2 月前    · 
纯真的冲锋衣  ·  数据争用(data race) ...·  2 月前    · 
大力的山羊  ·  python tkinter 选择器 ...·  1 年前    · 
豁达的马克杯  ·  table_constraint ...·  2 年前    · 
摘要:==use strict;use warnings;use Data::Dumper;my %hash = ( 'name' => 'zdd', 'id' => 1234,);print Dumper(\%hash); # use reference here to get a better output. == 摘要:1 local,my及our的区别2 use和require的区别3 -w, use warnings, ^W的区别,看perllexwarn4 ..与...的区别,看range operators5 q, qq, qr, qx 摘要:use strict;use warnings;use re 'debug';sub test { my $str = "123456789"; print join(":", split /(?<=...)/, $str);}test(); 摘要:用{}修饰变量名,可以防止 _ 被解释为变量名的一部分。sub test { my $head = "abc"; my $tail = "def"; my $full = "${head}_${tail}"; print $full, "\n";}直接写成下面这样,在strict模式下是无法通过的。my $full = "$head_$tail"; 摘要:CU上的翻译=head1 prototype Perl 可以通过函数元型在编译期进行有限的参数类型检验。如果你声明 sub mypush (+@) 那么 mypush() 对参数的处理就同内置的 push() 完全一样了。函数声明必须要在编译 相应函数调用之前告知编译器(编译器在编译函数调用时会对相应函数用 prototype 来查询它的元型来进行参数检验,并决定怎样编译此函数调用)。元型只在不用 & 调用 函数的时候起作用。就是说在语法上如果你想像内置函数一样调用,它就表现的像 内置函数一样。如果想用过时的风格通过 & 调用,那么编译器就无视函数声明。另外 元型在函数引用如 摘要:按q键退出,否则显示用户输入。#! /usr/local/bin/perl5use strict;use warnings;sub test { while (1) { # display the prompt print "sditest> "; # Get input form STDIN, this is short for my $get = chomp (my $get = <>); # Quit when user pressed 'q', otherwise print what ever... 摘要:在成块打印文本的时候特别有用。格式print < 数据输入.如果没有指定文件名,则其从标准输入流中自动打开和关闭一系列文件进行读入 Perl默认的内部变量 $- 当前页可打印的行数,属于Perl格式系统的一部分 $! 根据上下文内容返回错误号或... 摘要:总帮助模块帮助函数帮助内置函数帮助特殊变量帮助运算符帮助正则表达式帮助完整列表 perlsyn Perl syntax perldata Perl data structures perlop Perl operators and precedence perlsub Perl subroutines perlfunc Perl built-in functions perlopentut Perl open() ... 摘要:来自CUperl中our的用法require 5.006 当版本号小于 5.006 的时候,会返回失败,从而导致模块加载失败。 所以它的作用就是保证模块调用环境的 Perl 版本。 our 和 my 一样,都是对变量的声明, 不过 our 声明的是包全局变量, 而 my 声明的是词法变量。 不过,经过 our 声明的变量,它会变得像一个词法变量一样, 其实这也是 our 存在的目的:用来欺骗 strict pragma,使 strict 以为它是一个词法变量,其实却不是。 有一个简单的办法可以理解 our: 1,你就把 our 声明的变量和 my 声明的当成一样。 2,记住 our 和 ... 摘要:打开文件使用三参数的形式打开文件,这样非常便于区分模式和文件名,perl 5.6之后的版本都支持这种方式。#Open the 'txt' file for readingopen FH, '<', "$file_name.txt" or die "Error:$!\n";#Open the 'txt' file for writing. Creates the #file_name if it doesn't already exist #and will delete/overwrite a 摘要:or比||优先级低,除此之外,两者无区别。下面代码输出什么?my $a = 0; $a = $a or 1;print $a, "\n";$a = $a || 1;print $a, "\n";输出:01为什么呢?因为||, =, or 这三者优先级从左至右逐渐降低。所以,这样写可以。chomp(my $filename = shift( @ARGV ) || );但是这样写就不行chomp(my $filename = shift( @ARGV ) or );会出现如下错误Can't modi 摘要:注意:localtime获取的年份是相对于1900的偏移,需要加上1900,而localtime获取的month范围是0-11,需要加1。my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime(); $year += 1900; $mon++;my $date = "$year-$mon-$day"; print $date, "\n";== 摘要:$也能匹配\n见Perl语言入门,page 132, 注释61 /^.*$/能匹配"\n"么?能!因为$不仅能匹配行尾,也能匹配\n2 /^.*$/能匹配"b\n"么?能!.能b匹配. \n匹配$3 /^.*$/能匹配"\nb"么?不能!为什么?因为默认情况下,.不能匹配\n,把模式改一下变成/^.*$/s就可以了,/s表示.能匹配任意字符,包括\n====多行匹配/m看一个例子,这段代码输出hellomy $text = "hello, world,\nhello zdd,\nhello autumn";whil 摘要:来自CU的一道题有一组数据 ID 1 1 2 3 4 ID 2 1 2 3 4 ID 3 1 2 3 4 想变成 ID 1 1,2,3,4 ID 2 1,2,3,4 ID 3 1,2,3,4 请问该怎么写代码?谢谢了。我的代码,好复杂!use strict;use warnings;sub test { open SOURCE, '<', "d:/code/abc.txt" or die $!; open DEST, '>', "d:/code/def.txt" or die $!; my $items = q