• Perl最佳实践


    Perl best practice

    字符串引用

    1. 变量内插
      • “this is the $var”
      • qq(this is the $var)
    2. 字符串直接量
      • ‘this is the string’
      • q(this is the string)
    3. 变量内插包含单/双引号
      • “this double quote \” and the $var“
      • qq(this double quote “ and the $var)
    4. 字符串直接量含单引号
      • “this single quote ‘ and string”
      • q(this single quote ‘ and string)
    5. 空字符串
      • ‘’
      • q()
      • qq()
    6. 单个空格字符串
      • ‘ ’
      • “ ”
      • q( )
      • qq( )
    7. tab
      • ‘ ’
      • “\t”
      • qq(\t)

    perl长数字划分

    1. 5.8版本之前分隔符(_)只能放在三个整数之前
    2. 5.8版本后分隔符(_)可以放在任意数字之间

    perl怎样创建heredoc

    perl heredoc refernce

    image-20220219153933697

    >>’HEREDOC’; >和标识符之间没有空格

    第一个标识符HEREDOC;$,第二个标识符^HEREDOC$(懂我意思吧)

    ‘HEREDOC’:单引号标记的标识符变量不能转义

    “HEREDOC”:双引号标记的标识符变量可以转义

    heredoc内容必须靠左

    my $message = <<‘HEREDOC’;
    ...
    HEREDOC
    

    image-20220219184758062

    image-20220219184833127

    未修饰字(bareword)

    perl裸字参考博客

    perl裸字参考博客

    胖逗号 =>

    perl胖逗号参考博客

    创建key-value list时需要使用胖逗号(fat comma),胖逗号会移除key字符串必须加引号的限制。

    my %hash = (
    	sq => "chuang",
    	mw => "chuang",
    	xy => "yummy"
    );
    
    my %hash = (
    	'sq','chuang',
    	'mw','chuang',
    	'xy','yummy'
    );
    

    运算符及优先级

    perl运算符/优先级参考

    image-20220219193845608

    image-20220219194101680

    内置变量

    perl special variable reference

    image-20220219195655236

    image-20220219195741371

    image-20220219195843621

    image-20220219200206385

    image-20220219200322740

    切片/列表/数组

    控制结构

    # if block
    if() {
    	...
    }
    elsif(){
    	...
    }
    else {
    	...
    }
    
    # while block
    
    while(){
    	...
    }
    continue{
    	...
    }
    
    # until block
    
    until(){
    	...
    }
    continue{
    	...
    }
    
    # for block
    for(initial;judge;action){
    	...
    }
    

    image-20220219203930434

    # foreach block
    foreach my $var (list){
    	...
    }
    
  • 相关阅读:
    CF1132G
    CF1129B
    CF1131G
    CF1109D
    CF1110H
    CF1106F
    my.cnf 配置
    mysql 导入导出
    mysql 批量删除表数据
    国内开源镜像站
  • 原文地址:https://www.cnblogs.com/movit/p/15913600.html
Copyright © 2020-2023  润新知