zoukankan      html  css  js  c++  java
  • perl语言中的定义枚举

    perl语言中定义枚举变量和C语言中类似,默认都是从0开始,并依次递增1个单位;
    也可以重新自定义枚举变量的起始值,示例如下:

    定义枚举变量:

    use enum qw(Sun Mon Tue Wed Thu Fri Sat);
    # Sun == 0, Mon == 1, etc
    
    use enum qw(Forty=40 FortyOne Five=5 Six Seven);
    # Yes, you can change the start indexs at any time as in C
    
    use enum qw(:Prefix_ One Two Three);
    ## Creates Prefix_One, Prefix_Two, Prefix_Three
    
    use enum qw(:Letters_ A..Z);
    ## Creates Letters_A, Letters_B, Letters_C, ...
    
    use enum qw(
        :Months_=0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
        :Days_=0   Sun Mon Tue Wed Thu Fri Sat
    );

    测试代码:

    print "enum Wed val: ",Wed,"
    " ;
    print "enum FortyOne val: ",FortyOne,"
    " ;
    print "enum Prefix_Two val: ",Prefix_Two,"
    " ;
    print "enum Letters_A val: ",Letters_A,"
    " ;
    print "enum Months_Jan val: ",Months_Jan,"
    " ;
    print "enum Days_Sun val: ",Days_Sun,"
    " ;

    测试结果:

    enum Wed val: 3
    enum FortyOne val: 41
    enum Prefix_Two val: 1
    enum Letters_A val: 0
    enum Months_Jan val: 0
    enum Days_Sun val: 0

    更多参考资料:
    https://metacpan.org/pod/enum

  • 相关阅读:
    组合模式
    数据去重
    combiner
    合并文档
    对象锁 区别 类锁
    一个简单的死锁示例
    线程安全的单例模式
    线程安全与不安全(误解)
    tf.nn.max_pool 池化
    tf.nn.depthwise_conv2d 卷积
  • 原文地址:https://www.cnblogs.com/jinxiang1224/p/8468175.html
Copyright © 2011-2022 走看看